diff --git a/tools/virsh-completer-checkpoint.c b/tools/virsh-completer-checkpoint.c index ce9d32844dcd94286959519603c8e009fed60110..21e8bb5d3b8c78aeb1fd5e778e2f655a5b2698cc 100644 --- a/tools/virsh-completer-checkpoint.c +++ b/tools/virsh-completer-checkpoint.c @@ -56,8 +56,7 @@ virshCheckpointNameCompleter(vshControl *ctl, for (i = 0; i < ncheckpoints; i++) { const char *name = virDomainCheckpointGetName(checkpoints[i]); - if (VIR_STRDUP(ret[i], name) < 0) - goto error; + ret[i] = g_strdup(name); virshDomainCheckpointFree(checkpoints[i]); } diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index bb06f468d788dcc780aebf4c8d005b0cd84171cc..6bfa3ab58cf73fe7b7145a5b681add23a7e29acc 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -62,8 +62,7 @@ virshDomainNameCompleter(vshControl *ctl, for (i = 0; i < ndomains; i++) { const char *name = virDomainGetName(domains[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); @@ -181,10 +180,8 @@ virshDomainEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, if (VIR_ALLOC_N(tmp, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0) return NULL; - for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshDomainEventCallbacks[i].name) < 0) - return NULL; - } + for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) + tmp[i] = g_strdup(virshDomainEventCallbacks[i].name); ret = g_steal_pointer(&tmp); return ret; @@ -242,11 +239,9 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, if ((state = virXPathString("string(./link/@state)", ctxt)) && STREQ(state, "down")) { - if (VIR_STRDUP(tmp[0], "up") < 0) - return NULL; + tmp[0] = g_strdup("up"); } else { - if (VIR_STRDUP(tmp[0], "down") < 0) - return NULL; + tmp[0] = g_strdup("down"); } ret = g_steal_pointer(&tmp); diff --git a/tools/virsh-completer-interface.c b/tools/virsh-completer-interface.c index 6fae0f65841939e06225b7436fdb87a27ae7ea75..417374322af041231ede8bf365f1724c7b24f559 100644 --- a/tools/virsh-completer-interface.c +++ b/tools/virsh-completer-interface.c @@ -53,8 +53,7 @@ virshInterfaceNameCompleter(vshControl *ctl, for (i = 0; i < nifaces; i++) { const char *name = virInterfaceGetName(ifaces[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); diff --git a/tools/virsh-completer-network.c b/tools/virsh-completer-network.c index a3d8b71d194da0d710e85570b22e9683d0a220c6..0097fca7ccc1a99af93dc9bd11311ab0a5bac641 100644 --- a/tools/virsh-completer-network.c +++ b/tools/virsh-completer-network.c @@ -55,8 +55,7 @@ virshNetworkNameCompleter(vshControl *ctl, for (i = 0; i < nnets; i++) { const char *name = virNetworkGetName(nets[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); @@ -83,10 +82,8 @@ virshNetworkEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0) goto cleanup; - for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshNetworkEventCallbacks[i].name) < 0) - goto cleanup; - } + for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) + tmp[i] = g_strdup(virshNetworkEventCallbacks[i].name); ret = g_steal_pointer(&tmp); @@ -124,10 +121,11 @@ virshNetworkPortUUIDCompleter(vshControl *ctl, for (i = 0; i < nports; i++) { char uuid[VIR_UUID_STRING_BUFLEN]; - if (virNetworkPortGetUUIDString(ports[i], uuid) < 0 || - VIR_STRDUP(ret[i], uuid) < 0) + if (virNetworkPortGetUUIDString(ports[i], uuid) < 0) goto error; + ret[i] = g_strdup(uuid); + virNetworkPortFree(ports[i]); } VIR_FREE(ports); diff --git a/tools/virsh-completer-nodedev.c b/tools/virsh-completer-nodedev.c index 899c199902bb401130adb7abcc0e689130305a82..6b01941911a368ccc1562972ec539f4042db4094 100644 --- a/tools/virsh-completer-nodedev.c +++ b/tools/virsh-completer-nodedev.c @@ -53,8 +53,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl, for (i = 0; i < ndevs; i++) { const char *name = virNodeDeviceGetName(devs[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); @@ -81,10 +80,8 @@ virshNodeDeviceEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, if (VIR_ALLOC_N(tmp, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0) return NULL; - for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshNodeDeviceEventCallbacks[i].name) < 0) - return NULL; - } + for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) + tmp[i] = g_strdup(virshNodeDeviceEventCallbacks[i].name); ret = g_steal_pointer(&tmp); return ret; @@ -108,10 +105,8 @@ virshNodeDeviceCapabilityNameCompleter(vshControl *ctl, if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0) return NULL; - for (i = 0; i < VIR_NODE_DEV_CAP_LAST; i++) { - if (VIR_STRDUP(tmp[i], virNodeDevCapTypeToString(i)) < 0) - return NULL; - } + for (i = 0; i < VIR_NODE_DEV_CAP_LAST; i++) + tmp[i] = g_strdup(virNodeDevCapTypeToString(i)); return virshCommaStringListComplete(cap_str, (const char **)tmp); } diff --git a/tools/virsh-completer-nwfilter.c b/tools/virsh-completer-nwfilter.c index 5029becf099eda11179777d658fc6c42fbcc9d91..989a363847594522d67380f005108e10edb3a7a4 100644 --- a/tools/virsh-completer-nwfilter.c +++ b/tools/virsh-completer-nwfilter.c @@ -51,8 +51,7 @@ virshNWFilterNameCompleter(vshControl *ctl, for (i = 0; i < nnwfilters; i++) { const char *name = virNWFilterGetName(nwfilters[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); @@ -91,8 +90,7 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, for (i = 0; i < nbindings; i++) { const char *name = virNWFilterBindingGetPortDev(bindings[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c index ceb73eed0682650eb055a369d900d31bf4765ab4..bd9d9a980233488528561bdf3dac48afeeaeb7bf 100644 --- a/tools/virsh-completer-pool.c +++ b/tools/virsh-completer-pool.c @@ -56,8 +56,7 @@ virshStoragePoolNameCompleter(vshControl *ctl, for (i = 0; i < npools; i++) { const char *name = virStoragePoolGetName(pools[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); @@ -84,10 +83,8 @@ virshPoolEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0) return NULL; - for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshPoolEventCallbacks[i].name) < 0) - return NULL; - } + for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) + tmp[i] = g_strdup(virshPoolEventCallbacks[i].name); ret = g_steal_pointer(&tmp); return ret; @@ -111,10 +108,8 @@ virshPoolTypeCompleter(vshControl *ctl, if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_LAST + 1) < 0) return NULL; - for (i = 0; i < VIR_STORAGE_POOL_LAST; i++) { - if (VIR_STRDUP(tmp[i], virStoragePoolTypeToString(i)) < 0) - return NULL; - } + for (i = 0; i < VIR_STORAGE_POOL_LAST; i++) + tmp[i] = g_strdup(virStoragePoolTypeToString(i)); return virshCommaStringListComplete(type_str, (const char **)tmp); } diff --git a/tools/virsh-completer-secret.c b/tools/virsh-completer-secret.c index a533ac178f969e478a0d3955e90612ae45780722..bb02577c8267a05cc21edb15352dbf3869df11a9 100644 --- a/tools/virsh-completer-secret.c +++ b/tools/virsh-completer-secret.c @@ -52,9 +52,9 @@ virshSecretUUIDCompleter(vshControl *ctl, for (i = 0; i < nsecrets; i++) { char uuid[VIR_UUID_STRING_BUFLEN]; - if (virSecretGetUUIDString(secrets[i], uuid) < 0 || - VIR_STRDUP(tmp[i], uuid) < 0) + if (virSecretGetUUIDString(secrets[i], uuid) < 0) goto cleanup; + tmp[i] = g_strdup(uuid); } ret = g_steal_pointer(&tmp); @@ -81,10 +81,8 @@ virshSecretEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0) return NULL; - for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(tmp[i], virshSecretEventCallbacks[i].name) < 0) - return NULL; - } + for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) + tmp[i] = g_strdup(virshSecretEventCallbacks[i].name); ret = g_steal_pointer(&tmp); return ret; diff --git a/tools/virsh-completer-snapshot.c b/tools/virsh-completer-snapshot.c index 14bd7bc6e4a93fcbd54f03a1de216525ada0439d..aa1135d1323258b01b5215c70b45724d64b6a3f7 100644 --- a/tools/virsh-completer-snapshot.c +++ b/tools/virsh-completer-snapshot.c @@ -58,8 +58,7 @@ virshSnapshotNameCompleter(vshControl *ctl, for (i = 0; i < nsnapshots; i++) { const char *name = virDomainSnapshotGetName(snapshots[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); diff --git a/tools/virsh-completer-volume.c b/tools/virsh-completer-volume.c index f14570f23d9e41bae3d862b10af5263d024ec0c0..ad54261534ed2f4b7e8484868f006c23d924ea21 100644 --- a/tools/virsh-completer-volume.c +++ b/tools/virsh-completer-volume.c @@ -58,8 +58,7 @@ virshStorageVolNameCompleter(vshControl *ctl, for (i = 0; i < nvols; i++) { const char *name = virStorageVolGetName(vols[i]); - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; + tmp[i] = g_strdup(name); } ret = g_steal_pointer(&tmp); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index dd03c98a1654e847c06af9aa374aa16a38a2f70f..7e4bd895e5297bcb11869e89a21b4b833b7e401d 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -100,8 +100,7 @@ virshCommaStringListComplete(const char *input, if (input) { char *comma = NULL; - if (VIR_STRDUP(inputCopy, input) < 0) - return NULL; + inputCopy = g_strdup(input); if ((comma = strrchr(inputCopy, ','))) *comma = '\0'; @@ -119,9 +118,10 @@ virshCommaStringListComplete(const char *input, if (virStringListHasString((const char **)inputList, options[i])) continue; - if ((inputCopy && virAsprintf(&ret[nret], "%s,%s", inputCopy, options[i]) < 0) || - (!inputCopy && VIR_STRDUP(ret[nret], options[i]) < 0)) + if (inputCopy && virAsprintf(&ret[nret], "%s,%s", inputCopy, options[i]) < 0) return NULL; + if (!inputCopy) + ret[nret] = g_strdup(options[i]); nret++; } diff --git a/tools/virt-admin-completer.c b/tools/virt-admin-completer.c index b8602efaf921ba9e15449b9b5f55bd4205865022..25dacf51d8e8db9dbeeab829d5340da06b6b0370 100644 --- a/tools/virt-admin-completer.c +++ b/tools/virt-admin-completer.c @@ -53,8 +53,7 @@ vshAdmServerCompleter(vshControl *ctl, for (i = 0; i < nsrvs; i++) { const char *name = virAdmServerGetName(srvs[i]); - if (VIR_STRDUP(ret[i], name) < 0) - goto error; + ret[i] = g_strdup(name); virAdmServerFree(srvs[i]); } diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helper.c index eb2b2dfe9ef60d02df30d0ed9dc202f36e6574e0..ace8733968d3758218cfdcd74a528009af62f181 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -102,10 +102,7 @@ static int virLoginShellGetShellArgv(virConfPtr conf, if (rv == 0) { if (VIR_ALLOC_N(*shargv, 2) < 0) return -1; - if (VIR_STRDUP((*shargv)[0], "/bin/sh") < 0) { - VIR_FREE(*shargv); - return -1; - } + (*shargv)[0] = g_strdup("/bin/sh"); *shargvlen = 1; } else { *shargvlen = virStringListLength((const char *const *)shargv); @@ -347,10 +344,8 @@ main(int argc, char **argv) if (cmdstr) { if (VIR_REALLOC_N(shargv, shargvlen + 3) < 0) goto cleanup; - if (VIR_STRDUP(shargv[shargvlen++], "-c") < 0) - goto cleanup; - if (VIR_STRDUP(shargv[shargvlen++], cmdstr) < 0) - goto cleanup; + shargv[shargvlen++] = g_strdup("-c"); + shargv[shargvlen++] = g_strdup(cmdstr); shargv[shargvlen] = NULL; } @@ -366,15 +361,13 @@ main(int argc, char **argv) goto cleanup; } tmp = strrchr(shcmd, '/'); - if (VIR_STRDUP(shargv[0], tmp) < 0) - goto cleanup; + shargv[0] = g_strdup(tmp); shargv[0][0] = '-'; /* We're duping the string because the clearenv() * call will shortly release the pointer we get * back from getenv() right here */ - if (VIR_STRDUP(term, getenv("TERM")) < 0) - goto cleanup; + term = g_strdup(getenv("TERM")); /* A fork is required to create new process in correct pid namespace. */ if ((cpid = virFork()) < 0) diff --git a/tools/vsh-table.c b/tools/vsh-table.c index 8bd6d99778227ec7bc5e052a3df3fcf9ef3b2e8a..c2271a4e2dc14d7943dc8a437c3df29a6330016d 100644 --- a/tools/vsh-table.c +++ b/tools/vsh-table.c @@ -104,8 +104,7 @@ vshTableRowNew(const char *arg, va_list ap) while (arg) { char *tmp = NULL; - if (VIR_STRDUP(tmp, arg) < 0) - goto error; + tmp = g_strdup(arg); if (VIR_APPEND_ELEMENT(row->cells, row->ncells, tmp) < 0) { VIR_FREE(tmp); diff --git a/tools/vsh.c b/tools/vsh.c index 07eea4adf9202e6b55668505911411955b0f0a8f..3f8b7f21865a513f513d7fd4c8a3948c5b3f80fc 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -495,8 +495,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, opt->help = "string=value": treat boolean flag as alias of option and its default value */ sa_assert(!alias); - if (VIR_STRDUP(alias, opt->help) < 0) - goto cleanup; + alias = g_strdup(opt->help); name = alias; if ((value = strchr(name, '='))) { *value = '\0'; @@ -506,8 +505,7 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef *cmd, const char *name, opt->name); goto cleanup; } - if (VIR_STRDUP(*optstr, value + 1) < 0) - goto cleanup; + *optstr = g_strdup(value + 1); } continue; } @@ -3500,9 +3498,8 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd) vshReadlineInit(ctl); - if (!(rl_line_buffer = virBufferContentAndReset(&buf)) && - VIR_STRDUP(rl_line_buffer, "") < 0) - goto cleanup; + if (!(rl_line_buffer = virBufferContentAndReset(&buf))) + rl_line_buffer = g_strdup(""); /* rl_point is current cursor position in rl_line_buffer. * In our case it's at the end of the whole line. */