mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 10:03:49 +03:00
build: avoid useless virAsprintf
virAsprintf(&foo, "%s", bar) is wasteful compared to foo = strdup(bar) (or eventually, VIR_STRDUP(foo, bar), but one thing at a time...). Noticed while reviewing Laine's attempt to clean up broken qemu:///session. * cfg.mk (sc_prohibit_asprintf): Enhance rule. * src/esx/esx_storage_backend_vmfs.c (esxStorageBackendVMFSVolumeLookupByKey): Fix offender. * src/network/bridge_driver.c (networkStateInitialize): Likewise. * src/nwfilter/nwfilter_dhcpsnoop.c (virNWFilterSnoopDHCPOpen): Likewise. * src/storage/storage_backend_sheepdog.c (virStorageBackendSheepdogRefreshVol): Likewise. * src/util/vircgroup.c (virCgroupAddTaskStrController): Likewise. * src/util/virdnsmasq.c (addnhostsAdd): Likewise. * src/xen/block_stats.c (xenLinuxDomainDeviceID): Likewise. * src/xen/xen_driver.c (xenUnifiedConnectOpen): Likewise. * tools/virsh.c (vshGetTypedParamValue): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
5a3487dadb
commit
25ae3d3015
4
cfg.mk
4
cfg.mk
@ -378,10 +378,14 @@ sc_prohibit_strtol:
|
|||||||
$(_sc_search_regexp)
|
$(_sc_search_regexp)
|
||||||
|
|
||||||
# Use virAsprintf rather than as'printf since *strp is undefined on error.
|
# Use virAsprintf rather than as'printf since *strp is undefined on error.
|
||||||
|
# But for plain %s, virAsprintf is overkill compared to strdup.
|
||||||
sc_prohibit_asprintf:
|
sc_prohibit_asprintf:
|
||||||
@prohibit='\<v?a[s]printf\>' \
|
@prohibit='\<v?a[s]printf\>' \
|
||||||
halt='use virAsprintf, not as'printf \
|
halt='use virAsprintf, not as'printf \
|
||||||
$(_sc_search_regexp)
|
$(_sc_search_regexp)
|
||||||
|
@prohibit='virAsprintf.*, *"%s",' \
|
||||||
|
halt='use strdup instead of virAsprintf with "%s"' \
|
||||||
|
$(_sc_search_regexp)
|
||||||
|
|
||||||
# Prefer virSetUIDGID.
|
# Prefer virSetUIDGID.
|
||||||
sc_prohibit_setuid:
|
sc_prohibit_setuid:
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* esx_storage_backend_vmfs.c: ESX storage driver backend for
|
* esx_storage_backend_vmfs.c: ESX storage driver backend for
|
||||||
* managing VMFS datastores
|
* managing VMFS datastores
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
* Copyright (C) 2010-2011, 2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte@googlemail.com>
|
* Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte@googlemail.com>
|
||||||
* Copyright (C) 2012 Ata E Husain Bohra <ata.husain@hotmail.com>
|
* Copyright (C) 2012 Ata E Husain Bohra <ata.husain@hotmail.com>
|
||||||
*
|
*
|
||||||
@ -791,8 +791,7 @@ esxStorageBackendVMFSVolumeLookupByKey(virConnectPtr conn, const char *key)
|
|||||||
VIR_FREE(datastorePath);
|
VIR_FREE(datastorePath);
|
||||||
|
|
||||||
if (length < 1) {
|
if (length < 1) {
|
||||||
if (virAsprintf(&volumeName, "%s",
|
if (!(volumeName = strdup(fileInfo->path))) {
|
||||||
fileInfo->path) < 0) {
|
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -393,12 +393,9 @@ networkStateInitialize(bool privileged,
|
|||||||
}
|
}
|
||||||
VIR_FREE(userdir);
|
VIR_FREE(userdir);
|
||||||
|
|
||||||
userdir = virGetUserConfigDirectory();
|
base = virGetUserConfigDirectory();
|
||||||
if (virAsprintf(&base, "%s", userdir) == -1) {
|
if (!base)
|
||||||
VIR_FREE(userdir);
|
goto error;
|
||||||
goto out_of_memory;
|
|
||||||
}
|
|
||||||
VIR_FREE(userdir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configuration paths are either ~/.libvirt/qemu/... (session) or
|
/* Configuration paths are either ~/.libvirt/qemu/... (session) or
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* nwfilter_dhcpsnoop.c: support for DHCP snooping used by a VM
|
* nwfilter_dhcpsnoop.c: support for DHCP snooping used by a VM
|
||||||
* on an interface
|
* on an interface
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Red Hat, Inc.
|
* Copyright (C) 2012-2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2011,2012 IBM Corp.
|
* Copyright (C) 2011,2012 IBM Corp.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@ -1110,7 +1110,7 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac,
|
|||||||
* generate much more traffic than if we filtered by VM and
|
* generate much more traffic than if we filtered by VM and
|
||||||
* braodcast MAC as well
|
* braodcast MAC as well
|
||||||
*/
|
*/
|
||||||
if (virAsprintf(&ext_filter, "%s", filter) < 0) {
|
if (!(ext_filter = strdup(filter))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* storage_backend_sheepdog.c: storage backend for Sheepdog handling
|
* storage_backend_sheepdog.c: storage backend for Sheepdog handling
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2012 Wido den Hollander
|
* Copyright (C) 2012 Wido den Hollander
|
||||||
* Copyright (C) 2012 Frank Spijkerman
|
* Copyright (C) 2012 Frank Spijkerman
|
||||||
* Copyright (C) 2012 Sebastian Wiedenroth
|
* Copyright (C) 2012 Sebastian Wiedenroth
|
||||||
@ -268,7 +269,7 @@ virStorageBackendSheepdogRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(vol->target.path);
|
VIR_FREE(vol->target.path);
|
||||||
if (virAsprintf(&vol->target.path, "%s", vol->name) == -1) {
|
if (!(vol->target.path = strdup(vol->name))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -1027,7 +1027,7 @@ static int virCgroupAddTaskStrController(virCgroupPtr group,
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
char *endp;
|
char *endp;
|
||||||
|
|
||||||
if (virAsprintf(&str, "%s", pidstr) < 0)
|
if (!(str = strdup(pidstr)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
cur = str;
|
cur = str;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* virdnsmasq.c: Helper APIs for managing dnsmasq
|
* virdnsmasq.c: Helper APIs for managing dnsmasq
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2012 Red Hat, Inc.
|
* Copyright (C) 2007-2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2010 Satoru SATOH <satoru.satoh@gmail.com>
|
* Copyright (C) 2010 Satoru SATOH <satoru.satoh@gmail.com>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -118,7 +118,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
|
|||||||
if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
|
if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
|
||||||
goto alloc_error;
|
goto alloc_error;
|
||||||
|
|
||||||
if (virAsprintf(&addnhostsfile->hosts[idx].ip, "%s", ipstr) < 0)
|
if (!(addnhostsfile->hosts[idx].ip = strdup(ipstr)))
|
||||||
goto alloc_error;
|
goto alloc_error;
|
||||||
|
|
||||||
addnhostsfile->hosts[idx].nhostnames = 0;
|
addnhostsfile->hosts[idx].nhostnames = 0;
|
||||||
@ -128,7 +128,8 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
|
|||||||
if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0)
|
if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0)
|
||||||
goto alloc_error;
|
goto alloc_error;
|
||||||
|
|
||||||
if (virAsprintf(&addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames], "%s", name) < 0)
|
if (!(addnhostsfile->hosts[idx].hostnames[addnhostsfile->hosts[idx].nhostnames]
|
||||||
|
= strdup(name)))
|
||||||
goto alloc_error;
|
goto alloc_error;
|
||||||
|
|
||||||
VIR_FREE(ipstr);
|
VIR_FREE(ipstr);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Linux block and network stats.
|
* Linux block and network stats.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009 Red Hat, Inc.
|
* Copyright (C) 2007-2009, 2013 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -293,11 +293,11 @@ xenLinuxDomainDeviceID(int domid, const char *path)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (strlen(path) >= 5 && STRPREFIX(path, "/dev/"))
|
if (strlen(path) >= 5 && STRPREFIX(path, "/dev/"))
|
||||||
retval = virAsprintf(&mod_path, "%s", path);
|
mod_path = strdup(path);
|
||||||
else
|
else
|
||||||
retval = virAsprintf(&mod_path, "/dev/%s", path);
|
ignore_value(virAsprintf(&mod_path, "/dev/%s", path));
|
||||||
|
|
||||||
if (retval < 0) {
|
if (!mod_path) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ xenUnifiedConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int f
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (virAsprintf(&priv->saveDir, "%s", XEN_SAVE_DIR) == -1) {
|
if (!(priv->saveDir = strdup(XEN_SAVE_DIR))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -2181,7 +2181,7 @@ vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_TYPED_PARAM_BOOLEAN:
|
case VIR_TYPED_PARAM_BOOLEAN:
|
||||||
ret = virAsprintf(&str, "%s", item->value.b ? _("yes") : _("no"));
|
str = vshStrdup(ctl, item->value.b ? _("yes") : _("no"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_TYPED_PARAM_STRING:
|
case VIR_TYPED_PARAM_STRING:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user