
On 05/03/2013 04:53 PM, Michal Privoznik wrote:
--- tests/commandhelper.c | 10 ++++++++-- tests/commandtest.c | 2 +- tests/openvzutilstest.c | 6 ++++-- tests/qemumonitortestutils.c | 15 +++++++-------- tests/qemuxml2argvtest.c | 23 ++++++++++++----------- tests/qemuxmlnstest.c | 4 +++- tests/securityselinuxhelper.c | 9 +++------ tests/securityselinuxlabeltest.c | 3 +-- tests/securityselinuxtest.c | 9 +++++---- tests/storagebackendsheepdogtest.c | 6 ++---- tests/testutils.c | 4 +++- tests/testutilsqemu.c | 5 ++++- tests/vircgrouptest.c | 2 +- tests/virnetmessagetest.c | 21 +++++++++------------ tests/vmx2xmltest.c | 9 ++++----- tests/xml2vmxtest.c | 9 ++++----- 16 files changed, 71 insertions(+), 66 deletions(-)
diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 92f031f..1be5d66 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -31,6 +31,9 @@ #include "viralloc.h" #include "virfile.h" #include "testutils.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE
#ifndef WIN32
@@ -42,8 +45,11 @@ static int envsort(const void *a, const void *b) { const char *bstr = *bstrptr; char *aeq = strchr(astr, '='); char *beq = strchr(bstr, '='); - char *akey = strndup(astr, aeq - astr); - char *bkey = strndup(bstr, beq - bstr); + char *akey; + char *bkey; + if (VIR_STRNDUP(akey, astr, aeq - astr) < 0 || + VIR_STRNDUP(bkey, bstr, beq - bstr) < 0) + return -1; int ret = strcmp(akey, bkey); VIR_FREE(akey); VIR_FREE(bkey);
This is used as a comparison function for qsort, returning -1 doesn't mean an error. I'd suggest ignore_value(VIR_STRNDUP_QUIET()) instead, and dropping the #define.
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 1286273..7c86af3 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -288,10 +289,10 @@ mymain(void) VIR_FREE(driver.config->vncListen);
VIR_FREE(driver.config->vncTLSx509certdir); - if ((driver.config->vncTLSx509certdir = strdup("/etc/pki/libvirt-vnc")) == NULL) + if (VIR_STRDUP_QUIET(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc") < 0) return EXIT_FAILURE; VIR_FREE(driver.config->spiceTLSx509certdir); - if ((driver.config->spiceTLSx509certdir = strdup("/etc/pki/libvirt-spice")) == NULL) + if (VIR_STRDUP_QUIET(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0) return EXIT_FAILURE;
if ((driver.caps = testQemuCapsInit()) == NULL) @@ -299,16 +300,16 @@ mymain(void) if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver))) return EXIT_FAILURE; VIR_FREE(driver.config->stateDir); - if ((driver.config->stateDir = strdup("/nowhere")) == NULL) + if (VIR_STRDUP_QUIET(driver.config->stateDir, "/nowhere") < 0) return EXIT_FAILURE; VIR_FREE(driver.config->hugetlbfsMount); - if ((driver.config->hugetlbfsMount = strdup("/dev/hugepages")) == NULL) + if (VIR_STRDUP_QUIET(driver.config->hugetlbfsMount, "/dev/hugepages") < 0) return EXIT_FAILURE; VIR_FREE(driver.config->hugepagePath); - if ((driver.config->hugepagePath = strdup("/dev/hugepages/libvirt/qemu")) == NULL) + if (VIR_STRDUP_QUIET(driver.config->hugepagePath, "/dev/hugepages/libvirt/qemu") < 0) return EXIT_FAILURE; driver.config->spiceTLS = 1; - if (!(driver.config->spicePassword = strdup("123456"))) + if (VIR_STRDUP(driver.config->spicePassword, "123456") < 0)
VIR_STRDUP_QUIET
return EXIT_FAILURE; if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 || cpuMapOverride(map) < 0) {
ACK Jan