$(_sc_search_regexp)
# 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:
@prohibit='\<v?a[s]printf\>' \
halt='use virAsprintf, not as'printf \
$(_sc_search_regexp)
+ @prohibit='virAsprintf.*, *"%s",' \
+ halt='use strdup instead of virAsprintf with "%s"' \
+ $(_sc_search_regexp)
# Prefer virSetUIDGID.
sc_prohibit_setuid:
* esx_storage_backend_vmfs.c: ESX storage driver backend for
* 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) 2012 Ata E Husain Bohra <ata.husain@hotmail.com>
*
VIR_FREE(datastorePath);
if (length < 1) {
- if (virAsprintf(&volumeName, "%s",
- fileInfo->path) < 0) {
+ if (!(volumeName = strdup(fileInfo->path))) {
virReportOOMError();
goto cleanup;
}
}
VIR_FREE(userdir);
- userdir = virGetUserConfigDirectory();
- if (virAsprintf(&base, "%s", userdir) == -1) {
- VIR_FREE(userdir);
- goto out_of_memory;
- }
- VIR_FREE(userdir);
+ base = virGetUserConfigDirectory();
+ if (!base)
+ goto error;
}
/* Configuration paths are either ~/.libvirt/qemu/... (session) or
* nwfilter_dhcpsnoop.c: support for DHCP snooping used by a VM
* on an interface
*
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2012-2013 Red Hat, Inc.
* Copyright (C) 2011,2012 IBM Corp.
*
* Authors:
* generate much more traffic than if we filtered by VM and
* braodcast MAC as well
*/
- if (virAsprintf(&ext_filter, "%s", filter) < 0) {
+ if (!(ext_filter = strdup(filter))) {
virReportOOMError();
return NULL;
}
/*
* storage_backend_sheepdog.c: storage backend for Sheepdog handling
*
+ * Copyright (C) 2013 Red Hat, Inc.
* Copyright (C) 2012 Wido den Hollander
* Copyright (C) 2012 Frank Spijkerman
* Copyright (C) 2012 Sebastian Wiedenroth
}
VIR_FREE(vol->target.path);
- if (virAsprintf(&vol->target.path, "%s", vol->name) == -1) {
+ if (!(vol->target.path = strdup(vol->name))) {
virReportOOMError();
goto cleanup;
}
int rc = 0;
char *endp;
- if (virAsprintf(&str, "%s", pidstr) < 0)
+ if (!(str = strdup(pidstr)))
return -1;
cur = str;
/*
* 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>
*
* This library is free software; you can redistribute it and/or
if (VIR_ALLOC(addnhostsfile->hosts[idx].hostnames) < 0)
goto alloc_error;
- if (virAsprintf(&addnhostsfile->hosts[idx].ip, "%s", ipstr) < 0)
+ if (!(addnhostsfile->hosts[idx].ip = strdup(ipstr)))
goto alloc_error;
addnhostsfile->hosts[idx].nhostnames = 0;
if (VIR_REALLOC_N(addnhostsfile->hosts[idx].hostnames, addnhostsfile->hosts[idx].nhostnames + 1) < 0)
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;
VIR_FREE(ipstr);
/*
* 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
* modify it under the terms of the GNU Lesser General Public
*/
if (strlen(path) >= 5 && STRPREFIX(path, "/dev/"))
- retval = virAsprintf(&mod_path, "%s", path);
+ mod_path = strdup(path);
else
- retval = virAsprintf(&mod_path, "/dev/%s", path);
+ ignore_value(virAsprintf(&mod_path, "/dev/%s", path));
- if (retval < 0) {
+ if (!mod_path) {
virReportOOMError();
return -1;
}
}
#endif
- if (virAsprintf(&priv->saveDir, "%s", XEN_SAVE_DIR) == -1) {
+ if (!(priv->saveDir = strdup(XEN_SAVE_DIR))) {
virReportOOMError();
goto fail;
}
break;
case VIR_TYPED_PARAM_BOOLEAN:
- ret = virAsprintf(&str, "%s", item->value.b ? _("yes") : _("no"));
+ str = vshStrdup(ctl, item->value.b ? _("yes") : _("no"));
break;
case VIR_TYPED_PARAM_STRING: