[PATCHv4 16/17] util: use VIR_(APPEND|DELETE)_ELEMENT for ebtables rule lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/util/ebtables.c | 10 ++--------
 src/util/ebtables.h |  4 ++--
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/util/ebtables.c b/src/util/ebtables.c
index d3a8432..a8bbd94 100644
--- a/src/util/ebtables.c
+++ b/src/util/ebtables.c
@@ -114,11 +114,10 @@ ebtRulesAppend(ebtRules *rules,
 {
     ebtRule tmp = { .rule = rule, .argv = argv, .command_idx = command_idx };
 
-    if (VIR_REALLOC_N(rules->rules, rules->nrules+1) < 0) {
+    if (VIR_APPEND_ELEMENT(rules->rules, rules->nrules, tmp) < 0) {
         ebtRuleClear(&tmp);
         return ENOMEM;
     }
-    rules->rules[rules->nrules++] = tmp;
     return 0;
 }
 
@@ -137,12 +136,7 @@ ebtRulesRemove(ebtRules *rules,
 
     ebtRuleClear(&rules->rules[i]);
 
-    memmove(&rules->rules[i],
-            &rules->rules[i+1],
-            (rules->nrules - i - 1) * sizeof(ebtRule));
-
-    rules->nrules--;
-
+    VIR_DELETE_ELEMENT_INPLACE(rules->rules, i, rules->nrules);
     return 0;
 }
 
diff --git a/src/util/ebtables.h b/src/util/ebtables.h
index 49dc8a0..0381c25 100644
--- a/src/util/ebtables.h
+++ b/src/util/ebtables.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2009 IBM Corp.
- * Copyright (C) 2007, 2008 Red Hat, Inc.
+ * Copyright (C) 2007, 2008, 2012 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -38,7 +38,7 @@ typedef struct
     char  *table;
     char  *chain;
 
-    int      nrules;
+    size_t  nrules;
     ebtRule *rules;
 
 } ebtRules;
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]