From: Matthieu Coudron Date: Thu, 6 Feb 2014 14:29:08 +0000 (+0100) Subject: virDomainHostdev{Insert,Delete}: Replace VIR_REALLOC_N by VIR_{APPEND,DELETE}_ELEMENT X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=8fc98ac8cfbd092bf8142a0063031d69584caf9b;p=libvirt.git virDomainHostdev{Insert,Delete}: Replace VIR_REALLOC_N by VIR_{APPEND,DELETE}_ELEMENT With this change the code gets shorter and more readable. Signed-off-by: Matthieu Coudron --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 28e24f9555..7ad2a904eb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9868,10 +9868,8 @@ virDomainChrTargetTypeToString(int deviceType, int virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr hostdev) { - if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs + 1) < 0) - return -1; - def->hostdevs[def->nhostdevs++] = hostdev; - return 0; + + return VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev); } virDomainHostdevDefPtr @@ -9879,19 +9877,7 @@ virDomainHostdevRemove(virDomainDefPtr def, size_t i) { virDomainHostdevDefPtr hostdev = def->hostdevs[i]; - if (def->nhostdevs > 1) { - memmove(def->hostdevs + i, - def->hostdevs + i + 1, - sizeof(*def->hostdevs) * - (def->nhostdevs - (i + 1))); - def->nhostdevs--; - if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs) < 0) { - /* ignore, harmless */ - } - } else { - VIR_FREE(def->hostdevs); - def->nhostdevs = 0; - } + VIR_DELETE_ELEMENT(def->hostdevs, i, def->nhostdevs); return hostdev; }