]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: use g_strdup instead of VIR_STRDUP
authorJán Tomko <jtomko@redhat.com>
Sun, 20 Oct 2019 11:49:46 +0000 (13:49 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 21 Oct 2019 10:51:59 +0000 (12:51 +0200)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
39 files changed:
tests/bhyvexml2argvmock.c
tests/commandtest.c
tests/cputest.c
tests/domaincapstest.c
tests/nssmock.c
tests/openvzutilstest.c
tests/qemublocktest.c
tests/qemudomaincheckpointxml2xmltest.c
tests/qemufirmwaretest.c
tests/qemuhotplugtest.c
tests/qemumemlocktest.c
tests/qemumonitorjsontest.c
tests/qemumonitortestutils.c
tests/qemusecuritymock.c
tests/qemuvhostusertest.c
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c
tests/scsihosttest.c
tests/securityselinuxlabeltest.c
tests/securityselinuxtest.c
tests/storagebackendsheepdogtest.c
tests/testutils.c
tests/testutilsqemu.c
tests/vboxsnapshotxmltest.c
tests/viralloctest.c
tests/vircgrouptest.c
tests/virfilecachetest.c
tests/virfirewalltest.c
tests/virhostdevtest.c
tests/virnetmessagetest.c
tests/virpcimock.c
tests/virpcitest.c
tests/virscsitest.c
tests/virstoragetest.c
tests/virstringtest.c
tests/virtestmock.c
tests/virusbmock.c
tests/vmx2xmltest.c
tests/xml2vmxtest.c

index 717ceb4847c35cea46a9eca6718a7486f1de0c62..b0d38187f95d72b2e0bad0eebca58ea509734b39 100644 (file)
@@ -34,8 +34,7 @@ int virNetDevTapCreateInBridgePort(const char *brname G_GNUC_UNUSED,
                                    unsigned int fakeflags G_GNUC_UNUSED)
 {
     VIR_FREE(*ifname);
-    if (VIR_STRDUP(*ifname, "vnet0") < 0)
-        return -1;
+    *ifname = g_strdup("vnet0");
     return 0;
 }
 
@@ -43,8 +42,7 @@ char *virNetDevTapGetRealDeviceName(char *name G_GNUC_UNUSED)
 {
     char *fakename;
 
-    if (VIR_STRDUP(fakename, "faketapdev") < 0)
-        return NULL;
+    fakename = g_strdup("faketapdev");
     return fakename;
 }
 
index e79baa2946909e26343b4b11b7c15eaa4365c937..6ff2039ab115e2907925a9f263e532b70e2b235c 100644 (file)
@@ -686,10 +686,7 @@ static int test17(const void *unused G_GNUC_UNUSED)
         goto cleanup;
     }
     VIR_FREE(outbuf);
-    if (VIR_STRDUP(outbuf, "should not be leaked") < 0) {
-        puts("test framework failure");
-        goto cleanup;
-    }
+    outbuf = g_strdup("should not be leaked");
 
     virCommandSetErrorBuffer(cmd, &errbuf);
     if (errbuf != NULL) {
index ab68c3b4af111a5a75ef6c0418f23ca2ceb0df84..83b494857fb3e251637133290ec7bff82790574b 100644 (file)
@@ -492,9 +492,11 @@ cpuTestMakeQEMUCaps(const struct data *data)
     if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
         goto error;
 
-    if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, "host") < 0)
+    if (VIR_ALLOC(cpu) < 0)
         goto cleanup;
 
+    cpu->model = g_strdup("host");
+
     if (ARCH_IS_S390(data->arch))
         fail_no_props = false;
 
index 07bc99cc03a4803c179d441d31ef6e69c9f069af..61bc019671700e40a96b518ecf9d30e0435c2e86 100644 (file)
@@ -36,11 +36,11 @@ fillStringValues(virDomainCapsStringValuesPtr values, ...)
 
     va_start(list, values);
     while ((str = va_arg(list, const char *))) {
-        if (VIR_REALLOC_N(values->values, values->nvalues + 1) < 0 ||
-            VIR_STRDUP(values->values[values->nvalues], str) < 0) {
+        if (VIR_REALLOC_N(values->values, values->nvalues + 1) < 0) {
             ret = -1;
             break;
         }
+        values->values[values->nvalues] = g_strdup(str);
         values->nvalues++;
     }
     va_end(list);
@@ -95,9 +95,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
 
     if (machine) {
         VIR_FREE(domCaps->machine);
-        if (VIR_STRDUP(domCaps->machine,
-                       virQEMUCapsGetCanonicalMachine(qemuCaps, machine)) < 0)
-            goto cleanup;
+        domCaps->machine = g_strdup(virQEMUCapsGetCanonicalMachine(qemuCaps, machine));
     }
 
     if (!domCaps->machine)
@@ -153,9 +151,8 @@ fillXenCaps(virDomainCapsPtr domCaps)
 
     if (VIR_ALLOC(firmwares[0]) < 0 || VIR_ALLOC(firmwares[1]) < 0)
         goto cleanup;
-    if (VIR_STRDUP(firmwares[0]->name, "/usr/lib/xen/boot/hvmloader") < 0 ||
-        VIR_STRDUP(firmwares[1]->name, "/usr/lib/xen/boot/ovmf.bin") < 0)
-        goto cleanup;
+    firmwares[0]->name = g_strdup("/usr/lib/xen/boot/hvmloader");
+    firmwares[1]->name = g_strdup("/usr/lib/xen/boot/ovmf.bin");
 
     if (libxlMakeDomainCapabilities(domCaps, firmwares, 2) < 0)
         goto cleanup;
index 230044275ada8b944a59be8197bee7502eb92453..ea4b26ffabf4533ed7b5483f009325914316f156 100644 (file)
@@ -62,8 +62,7 @@ getrealpath(char **newpath,
             return -1;
         }
     } else {
-        if (VIR_STRDUP_QUIET(*newpath, path) < 0)
-            return -1;
+        *newpath = g_strdup(path);
     }
 
     return 0;
index 1fcd4d2caa49e10704b9b6a7a567e588bc7fe5f8..c15ce9a47b915ea72ddcbe56eba9a90811732d90 100644 (file)
@@ -99,10 +99,11 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED)
         "  </devices>\n"
         "</domain>\n";
 
-    if (!(def = virDomainDefNew()) ||
-        VIR_STRDUP(def->os.init, "/sbin/init") < 0)
+    if (!(def = virDomainDefNew()))
         goto cleanup;
 
+    def->os.init = g_strdup("/sbin/init");
+
     def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
     def->os.type = VIR_DOMAIN_OSTYPE_EXE;
 
index 0f073682ca56acf4c1446f1af2ade442f47e60bb..a8d2f57c6efcb85560ce89f43dddf647e04ef8bd 100644 (file)
@@ -161,8 +161,7 @@ testQemuDiskXMLToJSONFakeSecrets(virStorageSourcePtr src)
             return -1;
 
         srcpriv->secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES;
-        if (VIR_STRDUP(srcpriv->secinfo->s.aes.username, src->auth->username) < 0)
-            return -1;
+        srcpriv->secinfo->s.aes.username = g_strdup(src->auth->username);
 
         if (virAsprintf(&srcpriv->secinfo->s.aes.alias, "%s-secalias",
                         NULLSTR(src->nodestorage)) < 0)
index f6eb1f69b2283f387814d13a679da106b1a07b5c..4540f15dddd04f2334b45e7c43f713605c70e351 100644 (file)
@@ -63,8 +63,7 @@ testCompareXMLToXMLFiles(const char *inxml,
     if (flags & TEST_PARENT) {
         if (def->parent.parent_name)
             return -1;
-        if (VIR_STRDUP(def->parent.parent_name, "1525111885") < 0)
-            return -1;
+        def->parent.parent_name = g_strdup("1525111885");
     }
     if (flags & TEST_VDA_BITMAP) {
         virDomainCheckpointDiskDefPtr disk;
@@ -76,13 +75,11 @@ testCompareXMLToXMLFiles(const char *inxml,
             return -1;
         if (!disk->name) {
             disk->type = VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP;
-            if (VIR_STRDUP(disk->name, "vda") < 0)
-                return -1;
+            disk->name = g_strdup("vda");
         } else if (STRNEQ(disk->name, "vda")) {
             return -1;
         }
-        if (VIR_STRDUP(disk->bitmap, def->parent.name) < 0)
-            return -1;
+        disk->bitmap = g_strdup(def->parent.name);
     }
     if (flags & TEST_SIZE) {
         def->disks[0].size = 1048576;
index 9287ea554bf32317a8228c897017a856cfaae68b..ad7ed7a38432845978a8bdecb233426111d2678e 100644 (file)
@@ -70,8 +70,7 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED)
     };
     const size_t nexpected = G_N_ELEMENTS(expected);
 
-    if (VIR_STRDUP(fakehome, abs_srcdir "/qemufirmwaredata/home/user/.config") < 0)
-        return -1;
+    fakehome = g_strdup(abs_srcdir "/qemufirmwaredata/home/user/.config");
 
     setenv("XDG_CONFIG_HOME", fakehome, 1);
 
index d3da08875a663213b4306f0d82426d21a4b20fa7..4ff2b38c8336c40e8e8f16c68129350a5636869f 100644 (file)
@@ -597,10 +597,7 @@ mymain(void)
     struct testQemuHotplugCpuParams cpudata;
     char *fakerootdir;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        fprintf(stderr, "Out of memory\n");
-        abort();
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         fprintf(stderr, "Cannot create fakerootdir");
@@ -622,8 +619,7 @@ mymain(void)
     VIR_FREE(driver.config->spiceListen);
     VIR_FREE(driver.config->vncListen);
     /* some dummy values from 'config file' */
-    if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
-        return EXIT_FAILURE;
+    driver.config->spicePassword = g_strdup("123456");
 
     if (!(driver.domainEventState = virObjectEventStateNew()))
         return EXIT_FAILURE;
index c9484ac9cbf0d1d6f799287d3ddea12c67d5de92..490e2ef11f07285ae8cd472ebe752b82323063c7 100644 (file)
@@ -61,10 +61,7 @@ mymain(void)
     char *fakerootdir;
     virQEMUCapsPtr qemuCaps = NULL;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        fprintf(stderr, "Out of memory\n");
-        abort();
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         fprintf(stderr, "Cannot create fakerootdir");
index f754e4d94bf7113bf963d10d346f37ac44dd8603..c0eee921cf278d484c29f269b133720b342c3180 100644 (file)
@@ -2165,8 +2165,7 @@ testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *opaque)
         return -1;
 
     expectedInfo = (virDomainBlockIoTuneInfo) {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, NULL, 15, 16, 17, 18, 19, 20};
-    if (VIR_STRDUP(expectedInfo.group_name, "group14") < 0)
-        return -1;
+    expectedInfo.group_name = g_strdup("group14");
 
     if (qemuMonitorTestAddItem(test, "query-block", queryBlockReply) < 0 ||
         qemuMonitorTestAddItemParams(test, "block_set_io_throttle",
index 6b3aa97e3994d6f3d98aa6e90bdf823446f8f2cd..fb76bf185de4ccb15e3069fc95ef241aeea85289 100644 (file)
@@ -604,11 +604,8 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
     if (VIR_ALLOC(data) < 0)
         return -1;
 
-    if (VIR_STRDUP(data->command_name, command_name) < 0 ||
-        VIR_STRDUP(data->response, response) < 0) {
-        qemuMonitorTestHandlerDataFree(data);
-        return -1;
-    }
+    data->command_name = g_strdup(command_name);
+    data->response = g_strdup(response);
 
     return qemuMonitorTestAddHandler(test,
                                      qemuMonitorTestProcessCommandDefault,
@@ -692,9 +689,8 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test,
     if (VIR_ALLOC(data) < 0)
         return -1;
 
-    if (VIR_STRDUP(data->response, response) < 0 ||
-        VIR_STRDUP(data->cmderr, cmderr) < 0)
-        goto error;
+    data->response = g_strdup(response);
+    data->cmderr = g_strdup(cmderr);
 
     data->command_name = virJSONStringReformat(command, false);
     if (!data->command_name)
@@ -868,9 +864,8 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
     if (VIR_ALLOC(data) < 0)
         goto error;
 
-    if (VIR_STRDUP(data->command_name, cmdname) < 0 ||
-        VIR_STRDUP(data->response, response) < 0)
-        goto error;
+    data->command_name = g_strdup(cmdname);
+    data->response = g_strdup(response);
 
     while ((argname = va_arg(args, char *))) {
         size_t i;
@@ -885,9 +880,8 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
         if (VIR_EXPAND_N(data->args, data->nargs, 1))
             goto error;
 
-        if (VIR_STRDUP(data->args[i].argname, argname) < 0 ||
-            VIR_STRDUP(data->args[i].argval, argval) < 0)
-            goto error;
+        data->args[i].argname = g_strdup(argname);
+        data->args[i].argval = g_strdup(argval);
     }
 
     va_end(args);
@@ -984,10 +978,9 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test,
     if (VIR_ALLOC(data) < 0)
         goto error;
 
-    if (VIR_STRDUP(data->command_name, cmdname) < 0 ||
-        VIR_STRDUP(data->response, response) < 0 ||
-        VIR_STRDUP(data->expectArgs, cmdargs) < 0)
-        goto error;
+    data->command_name = g_strdup(cmdname);
+    data->response = g_strdup(response);
+    data->expectArgs = g_strdup(cmdargs);
 
     if (apostrophe) {
         char *tmp = data->expectArgs;
@@ -1065,8 +1058,7 @@ qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
         return NULL;
     }
 
-    if (VIR_STRDUP(tmpdir_template, "/tmp/libvirt_XXXXXX") < 0)
-        goto error;
+    tmpdir_template = g_strdup("/tmp/libvirt_XXXXXX");
 
     if (!(test->tmpdir = mkdtemp(tmpdir_template))) {
         virReportSystemError(errno, "%s",
index 8b857b0cc19ee91523c6f7d630783c40f6d2cab1..50435bbd02129f9081f73dfc7cf2b3848ee7c1ed 100644 (file)
@@ -146,8 +146,7 @@ virFileGetXAttrQuiet(const char *path,
         goto cleanup;
     }
 
-    if (VIR_STRDUP(*value, val) < 0)
-        goto cleanup;
+    *value = g_strdup(val);
 
     ret = 0;
  cleanup:
@@ -194,8 +193,7 @@ int virFileSetXAttr(const char *path,
     char *val;
 
     key = get_key(path, name);
-    if (VIR_STRDUP(val, value) < 0)
-        return -1;
+    val = g_strdup(value);
 
     virMutexLock(&m);
     init_syms();
index 0ee96d9ecc2d99f95c31144316b77e90ed4187d7..3e1890a88f75103bb2180524f5a7bdc0f764fb42 100644 (file)
@@ -68,8 +68,7 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED)
     };
     const size_t nexpected = G_N_ELEMENTS(expected);
 
-    if (VIR_STRDUP(fakehome, abs_srcdir "/qemuvhostuserdata/home/user/.config") < 0)
-        return -1;
+    fakehome = g_strdup(abs_srcdir "/qemuvhostuserdata/home/user/.config");
 
     setenv("XDG_CONFIG_HOME", fakehome, 1);
 
index 7bbc44451d6b277b5aaefcdd8697334096bb434d..122e14b0717518f0d7d75376c8b06202f43a209e 100644 (file)
@@ -43,8 +43,7 @@ fakeSecretGetValue(virSecretPtr obj G_GNUC_UNUSED,
                    unsigned int internalFlags G_GNUC_UNUSED)
 {
     char *secret;
-    if (VIR_STRDUP(secret, "AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A") < 0)
-        return NULL;
+    secret = g_strdup("AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A");
     *value_size = strlen(secret);
     return (unsigned char *) secret;
 }
@@ -517,9 +516,7 @@ testCompareXMLToArgv(const void *data)
         switch (vm->def->tpm->type) {
         case VIR_DOMAIN_TPM_TYPE_EMULATOR:
             VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path);
-            if (VIR_STRDUP(vm->def->tpm->data.emulator.source.data.file.path,
-                           "/dev/test") < 0)
-                goto cleanup;
+            vm->def->tpm->data.emulator.source.data.file.path = g_strdup("/dev/test");
             vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_FILE;
             break;
         case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
@@ -620,10 +617,7 @@ mymain(void)
     char *fakerootdir;
     virHashTablePtr capslatest = NULL;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        fprintf(stderr, "Out of memory\n");
-        abort();
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         fprintf(stderr, "Cannot create fakerootdir");
@@ -648,43 +642,33 @@ mymain(void)
     driver.privileged = true;
 
     VIR_FREE(driver.config->defaultTLSx509certdir);
-    if (VIR_STRDUP_QUIET(driver.config->defaultTLSx509certdir, "/etc/pki/qemu") < 0)
-        return EXIT_FAILURE;
+    driver.config->defaultTLSx509certdir = g_strdup("/etc/pki/qemu");
     VIR_FREE(driver.config->vncTLSx509certdir);
-    if (VIR_STRDUP_QUIET(driver.config->vncTLSx509certdir, "/etc/pki/libvirt-vnc") < 0)
-        return EXIT_FAILURE;
+    driver.config->vncTLSx509certdir = g_strdup("/etc/pki/libvirt-vnc");
     VIR_FREE(driver.config->spiceTLSx509certdir);
-    if (VIR_STRDUP_QUIET(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0)
-        return EXIT_FAILURE;
+    driver.config->spiceTLSx509certdir = g_strdup("/etc/pki/libvirt-spice");
     VIR_FREE(driver.config->chardevTLSx509certdir);
-    if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509certdir, "/etc/pki/libvirt-chardev") < 0)
-        return EXIT_FAILURE;
+    driver.config->chardevTLSx509certdir = g_strdup("/etc/pki/libvirt-chardev");
     VIR_FREE(driver.config->vxhsTLSx509certdir);
-    if (VIR_STRDUP_QUIET(driver.config->vxhsTLSx509certdir, "/etc/pki/libvirt-vxhs/dummy,path") < 0)
-        return EXIT_FAILURE;
+    driver.config->vxhsTLSx509certdir = g_strdup("/etc/pki/libvirt-vxhs/dummy,path");
     VIR_FREE(driver.config->nbdTLSx509certdir);
-    if (VIR_STRDUP_QUIET(driver.config->nbdTLSx509certdir, "/etc/pki/libvirt-nbd/dummy,path") < 0)
-        return EXIT_FAILURE;
+    driver.config->nbdTLSx509certdir = g_strdup("/etc/pki/libvirt-nbd/dummy,path");
 
     VIR_FREE(driver.config->hugetlbfs);
     if (VIR_ALLOC_N(driver.config->hugetlbfs, 2) < 0)
         return EXIT_FAILURE;
     driver.config->nhugetlbfs = 2;
-    if (VIR_STRDUP(driver.config->hugetlbfs[0].mnt_dir, "/dev/hugepages2M") < 0 ||
-        VIR_STRDUP(driver.config->hugetlbfs[1].mnt_dir, "/dev/hugepages1G") < 0)
-        return EXIT_FAILURE;
+    driver.config->hugetlbfs[0].mnt_dir = g_strdup("/dev/hugepages2M");
+    driver.config->hugetlbfs[1].mnt_dir = g_strdup("/dev/hugepages1G");
     driver.config->hugetlbfs[0].size = 2048;
     driver.config->hugetlbfs[0].deflt = true;
     driver.config->hugetlbfs[1].size = 1048576;
     driver.config->spiceTLS = 1;
-    if (VIR_STRDUP_QUIET(driver.config->spicePassword, "123456") < 0)
-        return EXIT_FAILURE;
+    driver.config->spicePassword = g_strdup("123456");
     VIR_FREE(driver.config->memoryBackingDir);
-    if (VIR_STRDUP_QUIET(driver.config->memoryBackingDir, "/var/lib/libvirt/qemu/ram") < 0)
-        return EXIT_FAILURE;
+    driver.config->memoryBackingDir = g_strdup("/var/lib/libvirt/qemu/ram");
     VIR_FREE(driver.config->nvramDir);
-    if (VIR_STRDUP(driver.config->nvramDir, "/var/lib/libvirt/qemu/nvram") < 0)
-        return EXIT_FAILURE;
+    driver.config->nvramDir = g_strdup("/var/lib/libvirt/qemu/nvram");
 
     capslatest = testQemuGetLatestCaps();
     if (!capslatest)
@@ -1222,9 +1206,7 @@ mymain(void)
     DO_TEST("graphics-vnc-tls", QEMU_CAPS_VNC, QEMU_CAPS_DEVICE_CIRRUS_VGA);
     DO_TEST_CAPS_VER("graphics-vnc-tls", "2.4.0");
     DO_TEST_CAPS_LATEST("graphics-vnc-tls");
-    if (VIR_STRDUP_QUIET(driver.config->vncTLSx509secretUUID,
-                         "6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea") < 0)
-        return EXIT_FAILURE;
+    driver.config->vncTLSx509secretUUID = g_strdup("6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea");
     DO_TEST_CAPS_LATEST("graphics-vnc-tls-secret");
     VIR_FREE(driver.config->vncTLSx509secretUUID);
     driver.config->vncSASL = driver.config->vncTLSx509verify = driver.config->vncTLS = 0;
@@ -1407,11 +1389,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_ISA_SERIAL,
             QEMU_CAPS_OBJECT_TLS_CREDS_X509);
     VIR_FREE(driver.config->chardevTLSx509certdir);
-    if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509certdir, "/etc/pki/libvirt-chardev") < 0)
-        return EXIT_FAILURE;
-    if (VIR_STRDUP_QUIET(driver.config->chardevTLSx509secretUUID,
-                         "6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea") < 0)
-        return EXIT_FAILURE;
+    driver.config->chardevTLSx509certdir = g_strdup("/etc/pki/libvirt-chardev");
+    driver.config->chardevTLSx509secretUUID = g_strdup("6fd3f62d-9fe7-4a4e-a869-7acd6376d8ea");
     DO_TEST("serial-tcp-tlsx509-secret-chardev",
             QEMU_CAPS_OBJECT_SECRET,
             QEMU_CAPS_DEVICE_ISA_SERIAL,
index 4c7ba98367f204eb5252994e152b3c892236971f..e7c029a74d0b2b232a233a43a06d753026aca740 100644 (file)
@@ -157,10 +157,7 @@ mymain(void)
     if (!capslatest)
         return EXIT_FAILURE;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        fprintf(stderr, "Out of memory\n");
-        abort();
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         fprintf(stderr, "Cannot create fakerootdir");
index c1a7e2d60316ec4874c75f808f510ae6a27245cf..35c7d93376b75087c595d3af45ecdf743ee8fea6 100644 (file)
@@ -253,10 +253,7 @@ mymain(void)
     char *fakerootdir = NULL;
     char *fakesysfsdir = NULL;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        fprintf(stderr, "Out of memory\n");
-        goto cleanup;
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         fprintf(stderr, "Cannot create fakerootdir");
index 6f9b5c0e70dac454e5c4dadbf37baed371db1458..9156403c51c1c34d024f8aabb3e44375f29215a1 100644 (file)
@@ -144,10 +144,7 @@ testSELinuxLoadFileList(const char *testname,
                         abs_builddir, line) < 0)
             goto cleanup;
         if (*tmp != '\0' && *tmp != '\n') {
-            if (VIR_STRDUP(context, tmp) < 0) {
-                VIR_FREE(file);
-                goto cleanup;
-            }
+            context = g_strdup(tmp);
 
             tmp = strchr(context, '\n');
             if (tmp)
@@ -270,8 +267,7 @@ testSELinuxCheckLabels(testSELinuxFile *files, size_t nfiles)
             if (errno == ENODATA) {
                 /* nothing to do */
             } else if (errno == EOPNOTSUPP) {
-                if (VIR_STRDUP(ctx, "EOPNOTSUPP") < 0)
-                    return -1;
+                ctx = g_strdup("EOPNOTSUPP");
             } else {
                 virReportSystemError(errno,
                                      "Cannot read label on %s",
index 5dccb708d885c8060d8f5ba720d364fde54c4580..6c8314de6b12f8fd3aedcd786e86166975e905f4 100644 (file)
@@ -77,17 +77,14 @@ testBuildDomainDef(bool dynamic,
     if (VIR_ALLOC(secdef) < 0)
         goto error;
 
-    if (VIR_STRDUP(secdef->model, "selinux") < 0)
-        goto error;
+    secdef->model = g_strdup("selinux");
 
     secdef->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC : VIR_DOMAIN_SECLABEL_STATIC;
-    if (label &&
-        VIR_STRDUP(secdef->label, label) < 0)
-        goto error;
+    if (label)
+        secdef->label = g_strdup(label);
 
-    if (baselabel &&
-        VIR_STRDUP(secdef->baselabel, baselabel) < 0)
-        goto error;
+    if (baselabel)
+        secdef->baselabel = g_strdup(baselabel);
 
     def->seclabels[0] = secdef;
     def->nseclabels++;
index 6504881920709a53df1db9df033f26fe6b02febc..a5403e71362cdaa59401ed4c140eae4efe9620a2 100644 (file)
@@ -63,8 +63,7 @@ test_node_info_parser(const void *opaque)
     if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
         return -1;
 
-    if (VIR_STRDUP(output, test.output) < 0)
-        return -1;
+    output = g_strdup(test.output);
 
     if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
         test.expected_return)
@@ -95,8 +94,7 @@ test_vdi_list_parser(const void *opaque)
     if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0)))
         return -1;
 
-    if (VIR_STRDUP(output, test.output) < 0)
-        return -1;
+    output = g_strdup(test.output);
 
     if (virStorageBackendSheepdogParseVdiList(vol, output) !=
         test.expected_return)
index 1c89d503d962a6276d11c316dbb30cc5de72ae46..a141abc91b2ad178b307c15d45a95687713ebb8a 100644 (file)
@@ -816,8 +816,7 @@ virTestSetEnvPath(void)
             virAsprintf(&new_path, "%s:%s", abs_builddir, path) < 0)
             goto cleanup;
     } else {
-        if (VIR_STRDUP(new_path, abs_builddir) < 0)
-            goto cleanup;
+        new_path = g_strdup(abs_builddir);
     }
 
     if (new_path &&
index e6eca5cb2e025c12130ee4dbbba4e9caac945270..0faa9cb84ab8e131db0bc60dbcd3de98c0ecbeae 100644 (file)
@@ -74,8 +74,7 @@ static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines)
         "pc-0.11", "pc", "pc-0.10", "isapc"
     };
 
-    if (VIR_STRDUP(canonical, x86_machines[0]) < 0)
-        return NULL;
+    canonical = g_strdup(x86_machines[0]);
 
     machines = virCapabilitiesAllocMachines(x86_machines,
                                             G_N_ELEMENTS(x86_machines));
@@ -503,9 +502,8 @@ virCapsPtr testQemuCapsInit(void)
         goto cleanup;
     caps->host.nsecModels = 1;
 
-    if (VIR_STRDUP(caps->host.secModels[0].model, "none") < 0 ||
-        VIR_STRDUP(caps->host.secModels[0].doi, "0") < 0)
-        goto cleanup;
+    caps->host.secModels[0].model = g_strdup("none");
+    caps->host.secModels[0].doi = g_strdup("0");
 
     if (!(cpuDefault = virCPUDefCopy(&cpuDefaultData)) ||
         !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)) ||
@@ -710,29 +708,22 @@ int qemuTestDriverInit(virQEMUDriver *driver)
     /* Overwrite some default paths so it's consistent for tests. */
     VIR_FREE(driver->config->libDir);
     VIR_FREE(driver->config->channelTargetDir);
-    if (VIR_STRDUP(driver->config->libDir, "/tmp/lib") < 0 ||
-        VIR_STRDUP(driver->config->channelTargetDir, "/tmp/channel") < 0)
-        goto error;
+    driver->config->libDir = g_strdup("/tmp/lib");
+    driver->config->channelTargetDir = g_strdup("/tmp/channel");
 
     if (!mkdtemp(statedir)) {
         virFilePrintf(stderr, "Cannot create fake stateDir");
         goto error;
     }
 
-    if (VIR_STRDUP(driver->config->stateDir, statedir) < 0) {
-        rmdir(statedir);
-        goto error;
-    }
+    driver->config->stateDir = g_strdup(statedir);
 
     if (!mkdtemp(configdir)) {
         virFilePrintf(stderr, "Cannot create fake configDir");
         goto error;
     }
 
-    if (VIR_STRDUP(driver->config->configDir, configdir) < 0) {
-        rmdir(configdir);
-        goto error;
-    }
+    driver->config->configDir = g_strdup(configdir);
 
     driver->caps = testQemuCapsInit();
     if (!driver->caps)
@@ -827,10 +818,9 @@ testQemuGetLatestCapsForArch(const char *arch,
     while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
         VIR_FREE(tmp);
 
-        if ((rc = VIR_STRDUP(tmp, STRSKIP(ent->d_name, "caps_"))) < 0)
-            goto cleanup;
+        tmp = g_strdup(STRSKIP(ent->d_name, "caps_"));
 
-        if (rc == 0)
+        if (!tmp)
             continue;
 
         if (!virStringStripSuffix(tmp, fullsuffix))
@@ -1051,8 +1041,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
         bool stripmachinealiases = false;
 
         if (STREQ(capsver, "latest")) {
-            if (VIR_STRDUP(capsfile, virHashLookup(capslatest, capsarch)) < 0)
-                goto cleanup;
+            capsfile = g_strdup(virHashLookup(capslatest, capsarch));
             stripmachinealiases = true;
         } else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml",
                                TEST_QEMU_CAPS_PATH, capsver, capsarch) < 0) {
index c70d7ab10016d02a3dcb03746b1ba2a94e86e268..3d6171e26686b12fd7004fd641c1c8b3b9230672 100644 (file)
@@ -58,9 +58,7 @@ testCompareXMLtoXMLFiles(const char *xml)
     int ret = -1;
     virVBoxSnapshotConfMachinePtr machine = NULL;
 
-    if (VIR_STRDUP(pathResult,
-                   abs_builddir "/vboxsnapshotxmldata/testResult.vbox") < 0)
-        return -1;
+    pathResult = g_strdup(abs_builddir "/vboxsnapshotxmldata/testResult.vbox");
 
     if (virFileMakePath(abs_builddir "/vboxsnapshotxmldata") < 0)
         goto cleanup;
index 75e639675bb83a76328e89535ab1929bca040370..c52483998b2b37e66a72e2dcce67ae57b95bee34 100644 (file)
@@ -409,8 +409,7 @@ testDispose(const void *opaque G_GNUC_UNUSED)
 
     VIR_DISPOSE_N(nums, nnums);
 
-    if (VIR_STRDUP(str, "test") < 0)
-        return -1;
+    str = g_strdup("test");
 
     VIR_DISPOSE_STRING(str);
 
index cecb15ae5b33f4a9f8ce8c62ae1dfdeccc4024c4..cec07580acc3c53af3e5c7847e2364c20ac4efa7 100644 (file)
@@ -992,10 +992,7 @@ initFakeFS(const char *mode,
 {
     char *fakerootdir;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        fprintf(stderr, "Out of memory\n");
-        abort();
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         fprintf(stderr, "Cannot create fakerootdir");
index e3c64019344b8484d4d88b6d8468696ccde51e52..6d280b3bec0d6f72a158273c0a4d482612d95394 100644 (file)
@@ -71,14 +71,9 @@ testFileCacheObjNew(const char *data)
     if (!(obj = virObjectNew(testFileCacheObjClass)))
         return NULL;
 
-    if (VIR_STRDUP(obj->data, data) < 0)
-        goto error;
+    obj->data = g_strdup(data);
 
     return obj;
-
- error:
-    virObjectUnref(obj);
-    return NULL;
 }
 
 
index 824e9f46c2299ea7b3ef8cdb575ccbf7222d1ee5..a5323a4256f74017ef9acbed088a348dd101aab3 100644 (file)
@@ -961,19 +961,17 @@ testFirewallQueryHook(const char *const*args,
                       const char *input G_GNUC_UNUSED,
                       char **output,
                       char **error G_GNUC_UNUSED,
-                      int *status,
+                      int *status G_GNUC_UNUSED,
                       void *opaque G_GNUC_UNUSED)
 {
     if (STREQ(args[0], IPTABLES_PATH) &&
         STREQ(args[1], "-L")) {
-        if (VIR_STRDUP(*output, TEST_FILTER_TABLE_LIST) < 0)
-            *status = 127;
+        *output = g_strdup(TEST_FILTER_TABLE_LIST);
     } else if (STREQ(args[0], IPTABLES_PATH) &&
                STREQ(args[1], "-t") &&
                STREQ(args[2], "nat") &&
                STREQ(args[3], "-L")) {
-        if (VIR_STRDUP(*output, TEST_NAT_TABLE_LIST) < 0)
-            *status = 127;
+        *output = g_strdup(TEST_NAT_TABLE_LIST);
     }
 }
 
index 8e21d3eae4cd475d3e2d79ae1fc6ddf187aa34a8..1f3f73043392fcfe90e79e00459959dd08d6ecbc 100644 (file)
@@ -117,8 +117,7 @@ myInit(void)
         goto cleanup;
     if ((mgr->activeSCSIHostdevs = virSCSIDeviceListNew()) == NULL)
         goto cleanup;
-    if (VIR_STRDUP(mgr->stateDir, TEST_STATE_DIR) < 0)
-        goto cleanup;
+    mgr->stateDir = g_strdup(TEST_STATE_DIR);
     if (virFileMakePath(mgr->stateDir) < 0)
         goto cleanup;
 
@@ -501,10 +500,7 @@ mymain(void)
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        fprintf(stderr, "Out of memory\n");
-        abort();
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         fprintf(stderr, "Cannot create fakerootdir");
index 53544abbdb28e473d728dd29f80cbb5372babd90..b0a01e8b9d08af0e2a4533310bad8a24291cf28d 100644 (file)
@@ -228,15 +228,16 @@ static int testMessagePayloadEncode(const void *args G_GNUC_UNUSED)
     err.level = VIR_ERR_ERROR;
 
     if (VIR_ALLOC(err.message) < 0 ||
-        VIR_STRDUP(*err.message, "Hello World") < 0 ||
         VIR_ALLOC(err.str1) < 0 ||
-        VIR_STRDUP(*err.str1, "One") < 0 ||
         VIR_ALLOC(err.str2) < 0 ||
-        VIR_STRDUP(*err.str2, "Two") < 0 ||
-        VIR_ALLOC(err.str3) < 0 ||
-        VIR_STRDUP(*err.str3, "Three") < 0)
+        VIR_ALLOC(err.str3) < 0)
         goto cleanup;
 
+    *err.message = g_strdup("Hello World");
+    *err.str1 = g_strdup("One");
+    *err.str2 = g_strdup("Two");
+    *err.str3 = g_strdup("Three");
+
     err.int1 = 1;
     err.int2 = 2;
 
index ba4256e2fb6c9981482f696ffa35f633e794b61c..d7dc0b00f04df2046dba2d5463b0a8d72de65465 100644 (file)
@@ -289,8 +289,7 @@ getrealpath(char **newpath,
             return -1;
         }
     } else {
-        if (VIR_STRDUP_QUIET(*newpath, path) < 0)
-            return -1;
+        *newpath = g_strdup(path);
     }
 
     return 0;
@@ -324,12 +323,12 @@ add_fd(int fd, const char *path)
               fd, path, cb.fd, cb.path);
     }
 
-    if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0 ||
-        VIR_STRDUP_QUIET(callbacks[nCallbacks].path, path) < 0) {
+    if (VIR_REALLOC_N_QUIET(callbacks, nCallbacks + 1) < 0) {
         errno = ENOMEM;
         goto cleanup;
     }
 
+    callbacks[nCallbacks].path = g_strdup(path);
     callbacks[nCallbacks++].fd = fd;
     ret = 0;
  cleanup:
@@ -477,10 +476,11 @@ pci_device_new_from_stub(const struct pciDevice *data)
     struct stat sb;
     bool configSrcExists = false;
 
-    if (!(devid = pci_address_format(&data->addr)) ||
-        VIR_STRDUP_QUIET(id, devid) < 0)
+    if (!(devid = pci_address_format(&data->addr)))
         ABORT_OOM();
 
+    id = g_strdup(devid);
+
     /* Replace ':' with '-' to create the config filename from the
      * device ID. The device ID cannot be used directly as filename
      * because it contains ':' and Windows does not allow ':' in
@@ -724,9 +724,10 @@ pci_driver_new(const char *name, ...)
     int vendor, device;
     g_autofree char *driverpath = NULL;
 
-    if (VIR_ALLOC_QUIET(driver) < 0 ||
-        VIR_STRDUP_QUIET(driver->name, name) < 0 ||
-        !(driverpath = pci_driver_get_path(driver, NULL, true)))
+    if (VIR_ALLOC_QUIET(driver) < 0)
+        ABORT_OOM();
+    driver->name = g_strdup(name);
+    if (!(driverpath = pci_driver_get_path(driver, NULL, true)))
         ABORT_OOM();
 
     if (virFileMakePath(driverpath) < 0)
index 4078dc4c694dac3e998a0f073ca90ffed83112b7..de2ffc7d41be47048d807ce35a24fa16853f68fe 100644 (file)
@@ -328,10 +328,7 @@ mymain(void)
     int ret = 0;
     char *fakerootdir;
 
-    if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
-        VIR_TEST_DEBUG("Out of memory");
-        abort();
-    }
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
     if (!mkdtemp(fakerootdir)) {
         VIR_TEST_DEBUG("Cannot create fakerootdir");
index d4019e82f76eb68c077acbc16063867a4d015f3a..99374cc80cc3a7a97a903865d8b3c77bde8ce587 100644 (file)
@@ -222,10 +222,7 @@ mymain(void)
 
     VIR_FREE(virscsi_prefix);
 
-    if (VIR_STRDUP(virscsi_prefix, tmpdir) < 0) {
-        ret = -1;
-        goto cleanup;
-    }
+    virscsi_prefix = g_strdup(tmpdir);
 
     if (virTestRun("test1", test1, NULL) < 0)
         ret = -1;
index 5d3edbc8544c5c5930cacb6e556fd0fca3d8c4e7..8f1d93fa5a8eb91212d03d30863f39f0e5434db1 100644 (file)
@@ -102,8 +102,7 @@ testStorageFileGetMetadata(const char *path,
         }
     }
 
-    if (VIR_STRDUP(def->path, path) < 0)
-        return NULL;
+    def->path = g_strdup(path);
 
     if (virStorageFileGetMetadata(def, uid, gid, false) < 0)
         return NULL;
@@ -480,8 +479,7 @@ testPathCanonicalizeReadlink(const char *path,
 
     for (i = 0; i < G_N_ELEMENTS(testPathCanonicalizeSymlinks); i++) {
         if (STREQ(path, testPathCanonicalizeSymlinks[i][0])) {
-            if (VIR_STRDUP(*linkpath, testPathCanonicalizeSymlinks[i][1]) < 0)
-                return -1;
+            *linkpath = g_strdup(testPathCanonicalizeSymlinks[i][1]);
 
             return 0;
         }
index 5d010f7f59f9d2314f96814c54ca3dc5b2e65f6d..1e408f27579bcecd76980c989f139e122bd49805 100644 (file)
@@ -718,8 +718,7 @@ static int testStripIPv6Brackets(const void *args)
     int ret = -1;
     char *res = NULL;
 
-    if (VIR_STRDUP(res, data->string) < 0)
-        goto cleanup;
+    res = g_strdup(data->string);
 
     virStringStripIPv6Brackets(res);
 
@@ -742,8 +741,7 @@ static int testStripControlChars(const void *args)
     int ret = -1;
     char *res = NULL;
 
-    if (VIR_STRDUP(res, data->string) < 0)
-        goto cleanup;
+    res = g_strdup(data->string);
 
     virStringStripControlChars(res);
 
@@ -772,8 +770,7 @@ static int testFilterChars(const void *args)
     int ret = -1;
     char *res = NULL;
 
-    if (VIR_STRDUP(res, data->string) < 0)
-        goto cleanup;
+    res = g_strdup(data->string);
 
     virStringFilterChars(res, data->valid);
 
index 9fe774836b96705d336d766e69aca09095419b66..e0f9c6c2a1236da06912b34391778df40ef51991 100644 (file)
@@ -122,8 +122,7 @@ checkPath(const char *path,
     } else {
         /* Yeah, our worst nightmares just became true. Path does
          * not exist. Cut off the last component and retry. */
-        if (VIR_STRDUP_QUIET(crippledPath, relPath ? relPath : path) < 0)
-            goto error;
+        crippledPath = g_strdup(relPath ? relPath : path);
 
         virFileRemoveLastComponent(crippledPath);
 
index f35ad407adfad48113293ef5e4843b25a010f580..cace140725a6a0aa678ad5fa47727b993088efef 100644 (file)
@@ -56,8 +56,8 @@ static char *get_fake_path(const char *real_path)
     if ((p = STRSKIP(real_path, USB_SYSFS)) &&
         virAsprintfQuiet(&path, "%s/%s/%s", abs_srcdir, FAKE_USB_SYSFS, p) < 0)
         goto error;
-    else if (!p && VIR_STRDUP_QUIET(path, real_path) < 0)
-        goto error;
+    else if (!p)
+        path = g_strdup(real_path);
 
     return path;
 
index 4c5d41aee553dc8e1db06366cf1ef66794b4a7b0..706fec7bac421acbdf776feb581b79dfaeb923f1 100644 (file)
@@ -142,8 +142,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED)
 
     if (STRPREFIX(fileName, "/vmfs/volumes/")) {
         /* Found absolute path referencing a file inside a datastore */
-        if (VIR_STRDUP(copyOfFileName, fileName) < 0)
-            goto cleanup;
+        copyOfFileName = g_strdup(fileName);
 
         /* Expected format: '/vmfs/volumes/<datastore>/<path>' */
         if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||
index 0cfdb1facf7681e82b5b47a767f10bb91cf6d71a..42ab4ed92990292f97cfe4575c81291bfd6ba94a 100644 (file)
@@ -153,8 +153,7 @@ testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED)
 
     if (STRPREFIX(src, "[")) {
         /* Found potential datastore path */
-        if (VIR_STRDUP(copyOfDatastorePath, src) < 0)
-            goto cleanup;
+        copyOfDatastorePath = g_strdup(src);
 
         /* Expected format: '[<datastore>] <path>' where <path> is optional */
         if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp == ']' ||