提交 506d313f 编写于 作者: J Ján Tomko

tools: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 29b1e859
......@@ -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]);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
}
......@@ -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);
......
......@@ -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);
}
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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++;
}
......
......@@ -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]);
}
......
......@@ -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)
......
......@@ -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);
......
......@@ -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. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册