Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- src/admin/admin_server_dispatch.c | 3 +-- src/hyperv/hyperv_driver.c | 13 ++++--------- src/hyperv/hyperv_util.c | 3 +-- src/libvirt-admin.c | 18 ++++++------------ src/libvirt.c | 16 +++++----------- src/openvz/openvz_conf.c | 14 ++++---------- src/openvz/openvz_driver.c | 12 ++++-------- src/phyp/phyp_driver.c | 25 ++++++++----------------- src/vmware/vmware_conf.c | 11 +++-------- src/vmware/vmware_driver.c | 6 ++---- src/vmx/vmx.c | 14 +++++++------- src/vz/vz_driver.c | 3 +-- src/vz/vz_sdk.c | 29 +++++++++-------------------- 13 files changed, 55 insertions(+), 112 deletions(-) diff --git a/src/admin/admin_server_dispatch.c b/src/admin/admin_server_dispatch.c index e56da3ba9f..0956084301 100644 --- a/src/admin/admin_server_dispatch.c +++ b/src/admin/admin_server_dispatch.c @@ -139,8 +139,7 @@ static int G_GNUC_WARN_UNUSED_RESULT make_nonnull_server(admin_nonnull_server *srv_dst, virNetServerPtr srv_src) { - if (VIR_STRDUP(srv_dst->name, virNetServerGetName(srv_src)) < 0) - return -1; + srv_dst->name = g_strdup(virNetServerGetName(srv_src)); return 0; } diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index d69542b500..542253b8b8 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -149,8 +149,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, /* Request credentials */ if (conn->uri->user != NULL) { - if (VIR_STRDUP(username, conn->uri->user) < 0) - goto cleanup; + username = g_strdup(conn->uri->user); } else { if (!(username = virAuthGetUsername(conn, auth, "hyperv", "administrator", @@ -846,13 +845,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return NULL; } - if (VIR_STRDUP(def->name, computerSystem->data.common->ElementName) < 0) - goto cleanup; + def->name = g_strdup(computerSystem->data.common->ElementName); if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) { - if (VIR_STRDUP(def->description, - virtualSystemSettingData->data.v1->Notes) < 0) - goto cleanup; + def->description = g_strdup(virtualSystemSettingData->data.v1->Notes); } else if (priv->wmiVersion == HYPERV_WMI_VERSION_V2 && virtualSystemSettingData->data.v2->Notes.data != NULL) { char **notes = (char **)virtualSystemSettingData->data.v2->Notes.data; @@ -935,8 +931,7 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxn for (computerSystem = computerSystemList; computerSystem != NULL; computerSystem = computerSystem->next) { - if (VIR_STRDUP(names[count], computerSystem->data.common->ElementName) < 0) - goto cleanup; + names[count] = g_strdup(computerSystem->data.common->ElementName); ++count; diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index 3b84713426..2425d6a0c6 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -54,8 +54,7 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) if (STRCASEEQ(queryParam->name, "transport")) { VIR_FREE((*parsedUri)->transport); - if (VIR_STRDUP((*parsedUri)->transport, queryParam->value) < 0) - goto cleanup; + (*parsedUri)->transport = g_strdup(queryParam->value); if (STRNEQ((*parsedUri)->transport, "http") && STRNEQ((*parsedUri)->transport, "https")) { diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c index 93c73615e3..9a18ea0f8b 100644 --- a/src/libvirt-admin.c +++ b/src/libvirt-admin.c @@ -112,8 +112,7 @@ getSocketPath(virURIPtr uri) if (STREQ(param->name, "socket")) { VIR_FREE(sock_path); - if (VIR_STRDUP(sock_path, param->value) < 0) - goto error; + sock_path = g_strdup(param->value); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown URI parameter '%s'"), param->name); @@ -140,8 +139,7 @@ getSocketPath(virURIPtr uri) } if (legacy) { - if (VIR_STRDUP(sockbase, "libvirt-admin-sock") < 0) - goto error; + sockbase = g_strdup("libvirt-admin-sock"); } else { if (virAsprintf(&sockbase, "%s-admin-sock", uri->scheme) < 0) goto error; @@ -177,8 +175,7 @@ virAdmGetDefaultURI(virConfPtr conf, char **uristr) { const char *defname = getenv("LIBVIRT_ADMIN_DEFAULT_URI"); if (defname && *defname) { - if (VIR_STRDUP(*uristr, defname) < 0) - return -1; + *uristr = g_strdup(defname); VIR_DEBUG("Using LIBVIRT_ADMIN_DEFAULT_URI '%s'", *uristr); } else { if (virConfGetValueString(conf, "uri_default", uristr) < 0) @@ -194,11 +191,9 @@ virAdmGetDefaultURI(virConfPtr conf, char **uristr) * 'libvirtd:///session' depending on the process's EUID. */ if (geteuid() == 0) { - if (VIR_STRDUP(*uristr, "libvirtd:///system") < 0) - return -1; + *uristr = g_strdup("libvirtd:///system"); } else { - if (VIR_STRDUP(*uristr, "libvirtd:///session") < 0) - return -1; + *uristr = g_strdup("libvirtd:///session"); } } } @@ -238,8 +233,7 @@ virAdmConnectOpen(const char *name, unsigned int flags) goto error; if (name) { - if (VIR_STRDUP(uristr, name) < 0) - goto error; + uristr = g_strdup(name); } else { if (virAdmGetDefaultURI(conf, &uristr) < 0) goto error; diff --git a/src/libvirt.c b/src/libvirt.c index 812cb9efde..33b43305a1 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -173,10 +173,7 @@ virConnectAuthCallbackDefault(virConnectCredentialPtr cred, } if (cred[i].type != VIR_CRED_EXTERNAL) { - if (VIR_STRDUP(cred[i].result, - STREQ(bufptr, "") && cred[i].defresult ? - cred[i].defresult : bufptr) < 0) - return -1; + cred[i].result = g_strdup(STREQ(bufptr, "") && cred[i].defresult ? cred[i].defresult : bufptr); cred[i].resultlen = strlen(cred[i].result); } } @@ -803,8 +800,7 @@ virConnectGetDefaultURI(virConfPtr conf, const char *defname = getenv("LIBVIRT_DEFAULT_URI"); if (defname && *defname) { VIR_DEBUG("Using LIBVIRT_DEFAULT_URI '%s'", defname); - if (VIR_STRDUP(*name, defname) < 0) - goto cleanup; + *name = g_strdup(defname); } else { if (virConfGetValueString(conf, "uri_default", name) < 0) goto cleanup; @@ -885,8 +881,7 @@ virConnectOpenInternal(const char *name, * if detectable. */ if (name) { - if (VIR_STRDUP(uristr, name) < 0) - goto failed; + uristr = g_strdup(name); } else { if (virConnectGetDefaultURI(conf, &uristr) < 0) goto failed; @@ -924,9 +919,8 @@ virConnectOpenInternal(const char *name, /* Avoid need for drivers to worry about NULLs, as * no one needs to distinguish "" vs NULL */ - if (ret->uri->path == NULL && - VIR_STRDUP(ret->uri->path, "") < 0) - goto failed; + if (ret->uri->path == NULL) + ret->uri->path = g_strdup(""); VIR_DEBUG("Split \"%s\" to URI components:\n" " scheme %s\n" diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index e5ef426329..4646308c48 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -348,8 +348,7 @@ openvzReadFSConf(virDomainDefPtr def, goto error; fs->type = VIR_DOMAIN_FS_TYPE_TEMPLATE; - if (VIR_STRDUP(fs->src->path, temp) < 0) - goto error; + fs->src->path = g_strdup(temp); } else { /* OSTEMPLATE was not found, VE was booted from a private dir directly */ ret = openvzReadVPSConfigParam(veid, "VE_PRIVATE", &temp); @@ -373,8 +372,7 @@ openvzReadFSConf(virDomainDefPtr def, VIR_FREE(veid_str); } - if (VIR_STRDUP(fs->dst, "/") < 0) - goto error; + fs->dst = g_strdup("/"); param = "DISKSPACE"; ret = openvzReadVPSConfigParam(veid, param, &temp); @@ -549,8 +547,7 @@ int openvzLoadDomains(struct openvz_driver *driver) } def->os.type = VIR_DOMAIN_OSTYPE_EXE; - if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) - goto cleanup; + def->os.init = g_strdup("/sbin/init"); ret = openvzReadVPSConfigParam(veid, "CPUS", &temp); if (ret < 0) { @@ -727,10 +724,7 @@ openvzReadConfigParam(const char *conf_file, const char *param, char **value) saveptr = NULL; if ((token = strtok_r(sf, "\"\t\n", &saveptr)) != NULL) { VIR_FREE(*value); - if (VIR_STRDUP(*value, token) < 0) { - err = 1; - break; - } + *value = g_strdup(token); /* keep going - last entry wins */ } } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index bf399986a7..017eec3081 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -118,10 +118,8 @@ openvzDomainDefPostParse(virDomainDefPtr def, void *parseOpaque G_GNUC_UNUSED) { /* fill the init path */ - if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) { - if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) - return -1; - } + if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) + def->os.init = g_strdup("/sbin/init"); return 0; } @@ -780,8 +778,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, /* if net is ethernet and the user has specified guest interface name, * let's use it; otherwise generate a new one */ if (net->ifname_guest) { - if (VIR_STRDUP(guest_ifname, net->ifname_guest) < 0) - goto cleanup; + guest_ifname = g_strdup(net->ifname_guest); } else { guest_ifname = openvzGenerateContainerVethName(veid); if (guest_ifname == NULL) { @@ -1507,8 +1504,7 @@ static int openvzConnectListDefinedDomains(virConnectPtr conn G_GNUC_UNUSED, continue; } snprintf(vpsname, sizeof(vpsname), "%d", veid); - if (VIR_STRDUP(names[got], vpsname) < 0) - goto out; + names[got] = g_strdup(vpsname); got ++; } diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 4527adc670..8b1d804233 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -946,8 +946,7 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, goto err; if (conn->uri->user != NULL) { - if (VIR_STRDUP(username, conn->uri->user) < 0) - goto err; + username = g_strdup(conn->uri->user); } else { if (!(username = virAuthGetUsername(conn, auth, "ssh", NULL, conn->uri->server))) @@ -1124,9 +1123,7 @@ phypConnectOpen(virConnectPtr conn, if (conn->uri->path[0] != '\0') { /* need to shift one byte in order to remove the first "/" of URI component */ - if (VIR_STRDUP(managed_system, - conn->uri->path + (conn->uri->path[0] == '/')) < 0) - goto failure; + managed_system = g_strdup(conn->uri->path + (conn->uri->path[0] == '/')); /* here we are handling only the first component of the path, * so skipping the second: @@ -1465,8 +1462,7 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, else goto cleanup; - if (VIR_STRDUP(backing_device, char_ptr) < 0) - goto cleanup; + backing_device = g_strdup(char_ptr); } else { backing_device = g_steal_pointer(&ret); } @@ -2228,8 +2224,7 @@ phypStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) goto cleanup; } - if (VIR_STRDUP(voldef.key, vol->key) < 0) - goto cleanup; + voldef.key = g_strdup(vol->key); voldef.type = VIR_STORAGE_POOL_LOGICAL; @@ -2338,8 +2333,7 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes, if (char_ptr) { *char_ptr = '\0'; - if (VIR_STRDUP(volumes[got++], volumes_list) < 0) - goto cleanup; + volumes[got++] = g_strdup(volumes_list); char_ptr++; volumes_list = char_ptr; } else { @@ -2532,8 +2526,7 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools, int npools) if (char_ptr) { *char_ptr = '\0'; - if (VIR_STRDUP(pools[got++], storage_pools) < 0) - goto cleanup; + pools[got++] = g_strdup(storage_pools); char_ptr++; storage_pools = char_ptr; } else { @@ -2985,8 +2978,7 @@ phypConnectListInterfaces(virConnectPtr conn, char **const names, int nnames) if (char_ptr) { *char_ptr = '\0'; - if (VIR_STRDUP(names[got++], networks) < 0) - goto cleanup; + names[got++] = g_strdup(networks); char_ptr++; networks = char_ptr; } else { @@ -3146,8 +3138,7 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames if (char_ptr) { *char_ptr = '\0'; - if (VIR_STRDUP(names[got++], domains) < 0) - goto cleanup; + names[got++] = g_strdup(domains); char_ptr++; domains = char_ptr; } else { diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 207af8fe81..8707f842ad 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -175,8 +175,7 @@ vmwareLoadDomains(struct vmware_driver *driver) pDomain = vm->privateData; - if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) - goto cleanup; + pDomain->vmxPath = g_strdup(vmxPath); vmwareDomainConfigDisplay(pDomain, vmdef); @@ -354,14 +353,10 @@ vmwareParsePath(const char *path, char **directory, char **filename) if (VIR_STRNDUP(*directory, path, separator - path - 1) < 0) goto error; - if (VIR_STRDUP(*filename, separator) < 0) { - VIR_FREE(*directory); - goto error; - } + *filename = g_strdup(separator); } else { - if (VIR_STRDUP(*filename, path) < 0) - goto error; + *filename = g_strdup(path); } return 0; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 912827a921..83974531d5 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -447,8 +447,7 @@ vmwareDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla goto cleanup; pDomain = vm->privateData; - if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) - goto cleanup; + pDomain->vmxPath = g_strdup(vmxPath); vmwareDomainConfigDisplay(pDomain, vmdef); @@ -708,8 +707,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, goto cleanup; pDomain = vm->privateData; - if (VIR_STRDUP(pDomain->vmxPath, vmxPath) < 0) - goto cleanup; + pDomain->vmxPath = g_strdup(vmxPath); vmwareDomainConfigDisplay(pDomain, vmdef); vmdef = NULL; diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index c9a80ba35d..0d1d87bac6 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1085,8 +1085,7 @@ virVMXHandleLegacySCSIDiskDriverName(virDomainDefPtr def, if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || !driver) return 0; - if (VIR_STRDUP(copy, driver) < 0) - return -1; + copy = g_strdup(driver); tmp = copy; for (; *tmp != '\0'; ++tmp) @@ -1812,13 +1811,15 @@ virVMXParseConfig(virVMXContext *ctx, if (ctx->datacenterPath || ctx->moref) { struct virVMXDomainDefNamespaceData *nsdata = NULL; - if (VIR_ALLOC(nsdata) < 0 || - VIR_STRDUP(nsdata->datacenterPath, ctx->datacenterPath) < 0 || - VIR_STRDUP(nsdata->moref, ctx->moref) < 0) { + if (VIR_ALLOC(nsdata) < 0) { virVMXDomainDefNamespaceFree(nsdata); goto cleanup; } + nsdata->datacenterPath = g_strdup(ctx->datacenterPath); + + nsdata->moref = g_strdup(ctx->moref); + def->ns = *virDomainXMLOptionGetNamespace(xmlopt); def->namespaceData = nsdata; } @@ -2839,8 +2840,7 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, goto cleanup; } - if (VIR_STRDUP((*def)->source->data.tcp.host, parsedUri->server) < 0) - goto cleanup; + (*def)->source->data.tcp.host = g_strdup(parsedUri->server); if (virAsprintf(&(*def)->source->data.tcp.service, "%d", parsedUri->port) < 0) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 76b23788b8..5b54f83b22 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -3015,8 +3015,7 @@ vzDomainMigratePrepare3Params(virConnectPtr conn, if (dname) { VIR_FREE(def->name); - if (VIR_STRDUP(def->name, dname) < 0) - goto cleanup; + def->name = g_strdup(dname); } if (virDomainMigratePrepare3ParamsEnsureACL(conn, def) < 0) diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 68284d53f7..e7c1676df9 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -501,8 +501,7 @@ prlsdkUUIDParse(const char *uuidstr, unsigned char *uuid) virCheckNonNullArgGoto(uuidstr, error); virCheckNonNullArgGoto(uuid, error); - if (VIR_STRDUP(tmp, uuidstr) < 0) - goto error; + tmp = g_strdup(uuidstr); tmp[strlen(tmp) - 1] = '\0'; @@ -774,10 +773,8 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk, fs->type = VIR_DOMAIN_FS_TYPE_VOLUME; if (VIR_ALLOC(fs->src->srcpool) < 0) goto cleanup; - if (VIR_STRDUP(fs->src->srcpool->pool, matches[1]) < 0) - goto cleanup; - if (VIR_STRDUP(fs->src->srcpool->volume, matches[2]) < 0) - goto cleanup; + fs->src->srcpool->pool = g_strdup(matches[1]); + fs->src->srcpool->volume = g_strdup(matches[2]); VIR_FREE(buf); } else { fs->type = VIR_DOMAIN_FS_TYPE_FILE; @@ -1054,9 +1051,7 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) * always up */ net->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP; net->type = VIR_DOMAIN_NET_TYPE_NETWORK; - if (VIR_STRDUP(net->data.network.name, - PARALLELS_DOMAIN_ROUTED_NETWORK_NAME) < 0) - goto cleanup; + net->data.network.name = g_strdup(PARALLELS_DOMAIN_ROUTED_NETWORK_NAME); return 0; } @@ -1078,9 +1073,7 @@ prlsdkGetNetInfo(PRL_HANDLE netAdapter, virDomainNetDefPtr net, bool isCt) if (emulatedType == PNA_ROUTED) { net->type = VIR_DOMAIN_NET_TYPE_NETWORK; - if (VIR_STRDUP(net->data.network.name, - PARALLELS_DOMAIN_ROUTED_NETWORK_NAME) < 0) - goto cleanup; + net->data.network.name = g_strdup(PARALLELS_DOMAIN_ROUTED_NETWORK_NAME); } else { char *netid = prlsdkGetStringParamVar(PrlVmDevNet_GetVirtualNetworkId, @@ -1224,8 +1217,7 @@ prlsdkGetSerialInfo(PRL_HANDLE serialPort, virDomainChrDefPtr chr) goto cleanup; if (!(uri = virURIParse(uristr))) goto cleanup; - if (VIR_STRDUP(chr->source->data.tcp.host, uri->server) < 0) - goto cleanup; + chr->source->data.tcp.host = g_strdup(uri->server); if (virAsprintf(&chr->source->data.tcp.service, "%d", uri->port) < 0) goto cleanup; chr->source->data.tcp.listen = socket_mode == PSP_SERIAL_SOCKET_SERVER; @@ -1236,12 +1228,10 @@ prlsdkGetSerialInfo(PRL_HANDLE serialPort, virDomainChrDefPtr chr) goto cleanup; if (!(uri = virURIParse(uristr))) goto cleanup; - if (VIR_STRDUP(chr->source->data.udp.bindHost, uri->server) < 0) - goto cleanup; + chr->source->data.udp.bindHost = g_strdup(uri->server); if (virAsprintf(&chr->source->data.udp.bindService, "%d", uri->port) < 0) goto cleanup; - if (VIR_STRDUP(chr->source->data.udp.connectHost, uri->server) < 0) - goto cleanup; + chr->source->data.udp.connectHost = g_strdup(uri->server); if (virAsprintf(&chr->source->data.udp.connectService, "%d", uri->port) < 0) goto cleanup; break; @@ -1526,8 +1516,7 @@ prlsdkConvertDomainType(PRL_HANDLE sdkdom, virDomainDefPtr def) break; case PVT_CT: def->os.type = VIR_DOMAIN_OSTYPE_EXE; - if (VIR_STRDUP(def->os.init, "/sbin/init") < 0) - return -1; + def->os.init = g_strdup("/sbin/init"); break; default: virReportError(VIR_ERR_INTERNAL_ERROR, -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list