Re: [libvirt] [PATCH 10/34] conf: use g_strdup instead of VIR_STRDUP

2019-10-22 Thread John Ferlan


[...]

>  virObjectEventPtr
> @@ -1635,11 +1587,8 @@ virDomainEventBlockThresholdNew(int id,
>   id, name, uuid)))
>  return NULL;
>  
> -if (VIR_STRDUP(ev->dev, dev) < 0 ||
> -VIR_STRDUP(ev->path, path) < 0) {
> -virObjectUnref(ev);
> -return NULL;
> -}
> +ev->dev = g_strdup(dev);
> +ev->path = g_strdup(path);
>  ev->threshold = threshold;
>  ev->excess = excess;
>  
> @@ -1986,12 +1935,13 @@ virDomainQemuMonitorEventNew(int id,
>  return NULL;
>  
>  /* event is mandatory, details are optional */
> -if (VIR_STRDUP(ev->event, event) <= 0)
> +if (!event)

@event is defined w/ ATTRIBUTE_NONNULL in src/conf/domain_event.h and
thus causes a coverity build error.

Perhaps the ATTRIBUTE_NONNULL can be removed.. at the very least should
an error be generated if it was removed? In order to avoid the failed
for some reason due to a NULL return. I didn't dig that deep - your call
on how to handle.

John


[...]

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



[libvirt] [PATCH 10/34] conf: use g_strdup instead of VIR_STRDUP

2019-10-20 Thread Ján Tomko
Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
 /* effectively dead code */
with:
  a = g_strdup(b);

Signed-off-by: Ján Tomko 
---
 src/conf/capabilities.c   |  33 +++
 src/conf/checkpoint_conf.c|   9 +-
 src/conf/cpu_conf.c   |  15 ++--
 src/conf/domain_audit.c   |  15 +---
 src/conf/domain_capabilities.c|   8 +-
 src/conf/domain_conf.c| 143 ++
 src/conf/domain_event.c   | 103 ++---
 src/conf/domain_nwfilter.c|  14 ++-
 src/conf/networkcommon_conf.c |   3 +-
 src/conf/node_device_conf.c   |  14 +--
 src/conf/node_device_util.c   |   3 +-
 src/conf/nwfilter_conf.c  |   4 +-
 src/conf/nwfilter_ipaddrmap.c |   3 +-
 src/conf/nwfilter_params.c|  12 +--
 src/conf/object_event.c   |  10 +--
 src/conf/snapshot_conf.c  |   9 +-
 src/conf/storage_conf.c   |  13 ++-
 src/conf/virchrdev.c  |   6 +-
 src/conf/virdomainmomentobjlist.c |   7 +-
 src/conf/virdomainobjlist.c   |  10 +--
 src/conf/virinterfaceobj.c|  11 +--
 src/conf/virnetworkobj.c  |   7 +-
 src/conf/virnodedeviceobj.c   |  10 +--
 src/conf/virnwfilterbindingdef.c  |  12 +--
 src/conf/virnwfilterobj.c |  11 +--
 src/conf/virstorageobj.c  |  28 ++
 26 files changed, 153 insertions(+), 360 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 1781c1df0a..697d464fe9 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -288,8 +288,7 @@ virCapabilitiesAddHostFeature(virCapsPtr caps,
  caps->host.nfeatures, 1) < 0)
 return -1;
 
-if (VIR_STRDUP(caps->host.features[caps->host.nfeatures], name) < 0)
-return -1;
+caps->host.features[caps->host.nfeatures] = g_strdup(name);
 caps->host.nfeatures++;
 
 return 0;
@@ -310,8 +309,7 @@ virCapabilitiesAddHostMigrateTransport(virCapsPtr caps,
  caps->host.nmigrateTrans, 1) < 0)
 return -1;
 
-if (VIR_STRDUP(caps->host.migrateTrans[caps->host.nmigrateTrans], name) < 
0)
-return -1;
+caps->host.migrateTrans[caps->host.nmigrateTrans] = g_strdup(name);
 caps->host.nmigrateTrans++;
 
 return 0;
@@ -328,8 +326,7 @@ int
 virCapabilitiesSetNetPrefix(virCapsPtr caps,
 const char *prefix)
 {
-if (VIR_STRDUP(caps->host.netprefix, prefix) < 0)
-return -1;
+caps->host.netprefix = g_strdup(prefix);
 
 return 0;
 }
@@ -423,11 +420,11 @@ virCapabilitiesAllocMachines(const char *const *names, 
int nnames)
 return NULL;
 
 for (i = 0; i < nnames; i++) {
-if (VIR_ALLOC(machines[i]) < 0 ||
-VIR_STRDUP(machines[i]->name, names[i]) < 0) {
+if (VIR_ALLOC(machines[i]) < 0) {
 virCapabilitiesFreeMachines(machines, nnames);
 return NULL;
 }
+machines[i]->name = g_strdup(names[i]);
 }
 
 return machines;
@@ -486,9 +483,8 @@ virCapabilitiesAddGuest(virCapsPtr caps,
 guest->arch.id = arch;
 guest->arch.wordsize = virArchGetWordSize(arch);
 
-if (VIR_STRDUP(guest->arch.defaultInfo.emulator, emulator) < 0 ||
-VIR_STRDUP(guest->arch.defaultInfo.loader, loader) < 0)
-goto error;
+guest->arch.defaultInfo.emulator = g_strdup(emulator);
+guest->arch.defaultInfo.loader = g_strdup(loader);
 
 if (VIR_RESIZE_N(caps->guests, caps->nguests_max,
  caps->nguests, 1) < 0)
@@ -534,9 +530,8 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
 goto error;
 
 dom->type = hvtype;
-if (VIR_STRDUP(dom->info.emulator, emulator) < 0 ||
-VIR_STRDUP(dom->info.loader, loader) < 0)
-goto error;
+dom->info.emulator = g_strdup(emulator);
+dom->info.loader = g_strdup(loader);
 
 if (VIR_RESIZE_N(guest->arch.domains, guest->arch.ndomains_max,
  guest->arch.ndomains, 1) < 0)
@@ -577,8 +572,7 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
 if (VIR_ALLOC(feature) < 0)
 goto no_memory;
 
-if (VIR_STRDUP(feature->name, name) < 0)
-goto no_memory;
+feature->name = g_strdup(name);
 feature->defaultOn = defaultOn;
 feature->toggle = toggle;
 
@@ -612,11 +606,8 @@ 
virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel,
 if (type == NULL || label == NULL)
 return -1;
 
-if (VIR_STRDUP(t, type) < 0)
-goto no_memory;
-
-if (VIR_STRDUP(l, label) < 0)
-goto no_memory;
+t = g_strdup(type);
+l = g_strdup(label);
 
 if (VIR_EXPAND_N(secmodel->labels, secmodel->nlabels, 1) < 0)
 goto no_memory;
diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index b254dce7fd..4fa743e0b0 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -275,8 +275,7 @@ 
virDomainCheckpointDefAssignBitmapNames(virDomainCheckpo