]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: use g_new0 instead of VIR_ALLOC_N
authorJán Tomko <jtomko@redhat.com>
Tue, 22 Sep 2020 23:04:17 +0000 (01:04 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 23 Sep 2020 14:49:01 +0000 (16:49 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
17 files changed:
tests/commandtest.c
tests/domaincapstest.c
tests/fdstreamtest.c
tests/qemuxml2argvtest.c
tests/securityselinuxlabeltest.c
tests/securityselinuxtest.c
tests/testutils.c
tests/testutilsqemu.c
tests/vircgrouptest.c
tests/vircryptotest.c
tests/virhostcputest.c
tests/virnetmessagetest.c
tests/virnetsockettest.c
tests/virnettlshelpers.c
tests/virstringtest.c
tests/xlconfigtest.c
tests/xmconfigtest.c

index cbbcda4e5f1471d65cf9bef246d47bd3fd93e3a3..df86725f0e7befa576450ab49de606c082475d80 100644 (file)
@@ -1057,10 +1057,9 @@ static int test27(const void *unused G_GNUC_UNUSED)
         "%s%s%s" \
         "END STDERR\n"
 
-    if (VIR_ALLOC_N(buffer0, buflen) < 0 ||
-        VIR_ALLOC_N(buffer1, buflen) < 0 ||
-        VIR_ALLOC_N(buffer2, buflen) < 0)
-        goto cleanup;
+    buffer0 = g_new0(char, buflen);
+    buffer1 = g_new0(char, buflen);
+    buffer2 = g_new0(char, buflen);
 
     memset(buffer0, 'H', buflen - 2);
     buffer0[buflen - 2] = '\n';
index f817ed5452c15192adfccab90ec3eaaf786a8249..7a082705c6a1b6526141765f69386b339712e08b 100644 (file)
@@ -147,8 +147,7 @@ fillXenCaps(virDomainCapsPtr domCaps)
     virFirmwarePtr *firmwares;
     int ret = -1;
 
-    if (VIR_ALLOC_N(firmwares, 2) < 0)
-        return ret;
+    firmwares = g_new0(virFirmwarePtr, 2);
 
     firmwares[0] = g_new0(virFirmware, 1);
     firmwares[1] = g_new0(virFirmware, 1);
index 83973137e7fc3c1b9b1d4c96bec0046d0dd9daa6..7a2fe27477392ce115bd50ccbfe8dd22c2721bdb 100644 (file)
@@ -54,9 +54,8 @@ static int testFDStreamReadCommon(const char *scratchdir, bool blocking)
     if (!(conn = virConnectOpen("test:///default")))
         goto cleanup;
 
-    if (VIR_ALLOC_N(pattern, PATTERN_LEN) < 0 ||
-        VIR_ALLOC_N(buf, PATTERN_LEN) < 0)
-        goto cleanup;
+    pattern = g_new0(char, PATTERN_LEN);
+    buf = g_new0(char, PATTERN_LEN);
 
     for (i = 0; i < PATTERN_LEN; i++)
         pattern[i] = i;
@@ -185,9 +184,8 @@ static int testFDStreamWriteCommon(const char *scratchdir, bool blocking)
     if (!(conn = virConnectOpen("test:///default")))
         goto cleanup;
 
-    if (VIR_ALLOC_N(pattern, PATTERN_LEN) < 0 ||
-        VIR_ALLOC_N(buf, PATTERN_LEN) < 0)
-        goto cleanup;
+    pattern = g_new0(char, PATTERN_LEN);
+    buf = g_new0(char, PATTERN_LEN);
 
     for (i = 0; i < PATTERN_LEN; i++)
         pattern[i] = i;
index e93948e3fc62ed7cb18dd7b57d84534d881f9936..463e4c003d917192ccc5d8f391813fb0c95aaa7f 100644 (file)
@@ -753,8 +753,7 @@ mymain(void)
     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->hugetlbfs = g_new0(virHugeTLBFS, 2);
     driver.config->nhugetlbfs = 2;
     driver.config->hugetlbfs[0].mnt_dir = g_strdup("/dev/hugepages2M");
     driver.config->hugetlbfs[1].mnt_dir = g_strdup("/dev/hugepages1G");
index 2989a668b7563b0efa382039417ee04870d25d6d..168acc2bdfa373cc03e5122ed7552021fdf18e59 100644 (file)
@@ -114,8 +114,7 @@ testSELinuxLoadFileList(const char *testname,
     if (!(fp = fopen(path, "r")))
         goto cleanup;
 
-    if (VIR_ALLOC_N(line, 1024) < 0)
-        goto cleanup;
+    line = g_new0(char, 1024);
 
     while (!feof(fp)) {
         char *file = NULL, *context = NULL, *tmp;
index 297cc0e53d1997a4e8937d18beb71320c14aee47..a75ff495ebbe9eb11ac039227d9b398b91f4fa5f 100644 (file)
@@ -71,8 +71,7 @@ testBuildDomainDef(bool dynamic,
         goto error;
 
     def->virtType = VIR_DOMAIN_VIRT_KVM;
-    if (VIR_ALLOC_N(def->seclabels, 1) < 0)
-        goto error;
+    def->seclabels = g_new0(virSecurityLabelDefPtr, 1);
 
     secdef = g_new0(virSecurityLabelDef, 1);
 
index 3f53f635fc29f93796be2c833856d505b2789dd4..b747f65eea5817c93eb5cb1bc186c6d969393b14 100644 (file)
@@ -211,10 +211,7 @@ virTestLoadFile(const char *file, char **buf)
 
     tmplen = buflen = st.st_size + 1;
 
-    if (VIR_ALLOC_N(*buf, buflen) < 0) {
-        VIR_FORCE_FCLOSE(fp);
-        return -1;
-    }
+    *buf = g_new0(char, buflen);
 
     tmp = *buf;
     (*buf)[0] = '\0';
@@ -977,8 +974,7 @@ virTestCapsBuildNUMATopology(int seq)
 
     id = 0;
     for (cell_id = 0; cell_id < MAX_CELLS; cell_id++) {
-        if (VIR_ALLOC_N(cell_cpus, MAX_CPUS_IN_CELL) < 0)
-            goto error;
+        cell_cpus = g_new0(virCapsHostNUMACellCPU, MAX_CPUS_IN_CELL);
 
         for (core_id = 0; core_id < MAX_CPUS_IN_CELL; core_id++) {
             cell_cpus[core_id].id = id + core_id;
index 51ac59bade2a9daa66ef412cb42018a84a16df81..eb37bbfdad9e742b2f6d07d8b697332c42d83549 100644 (file)
@@ -204,8 +204,7 @@ virCapsPtr testQemuCapsInit(void)
 
     /* Add dummy 'none' security_driver. This is equal to setting
      * security_driver = "none" in qemu.conf. */
-    if (VIR_ALLOC_N(caps->host.secModels, 1) < 0)
-        goto cleanup;
+    caps->host.secModels = g_new0(virCapsHostSecModel, 1);
     caps->host.nsecModels = 1;
 
     caps->host.secModels[0].model = g_strdup("none");
@@ -459,8 +458,7 @@ testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps,
     virGICCapability *gicCapabilities = NULL;
     size_t ngicCapabilities = 0;
 
-    if (VIR_ALLOC_N(gicCapabilities, 2) < 0)
-        return -1;
+    gicCapabilities = g_new0(virGICCapability, 2);
 
 # define IMPL_BOTH \
          VIR_GIC_IMPLEMENTATION_KERNEL|VIR_GIC_IMPLEMENTATION_EMULATED
index 44e72cbfa95428940851432741bc30e37c8a508f..e5be5561042fbb31d066e7231934e69886fbea97 100644 (file)
@@ -708,8 +708,7 @@ static int testCgroupGetPercpuStats(const void *args G_GNUC_UNUSED)
         635751356ULL, 0, 0, 0, 0, 0, 0, 0,
     };
 
-    if (VIR_ALLOC_N(params, EXPECTED_NCPUS) < 0)
-        goto cleanup;
+    params = g_new0(virTypedParameter, EXPECTED_NCPUS);
 
     if ((rv = virCgroupNewPartition("/virtualmachines", true,
                                     (1 << VIR_CGROUP_CONTROLLER_CPU) |
index 42ef0b8900c754067ff3769a8b73b2e54c8fb75a..90140077cf563113d14bffded896c49a327f06d4 100644 (file)
@@ -83,9 +83,8 @@ testCryptoEncrypt(const void *opaque)
         return EXIT_AM_SKIP;
     }
 
-    if (VIR_ALLOC_N(enckey, enckeylen) < 0 ||
-        VIR_ALLOC_N(iv, ivlen) < 0)
-        goto cleanup;
+    enckey = g_new0(uint8_t, enckeylen);
+    iv = g_new0(uint8_t, ivlen);
 
     if (virRandomBytes(enckey, enckeylen) < 0 ||
         virRandomBytes(iv, ivlen) < 0) {
index 7b83c7ae5d4e1482f772cc7af05a96b481c5d27e..786a363e48d27d191c20b15ad5c7aacab628ffb0 100644 (file)
@@ -124,8 +124,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
     if (virHostCPUGetStatsLinux(NULL, 0, NULL, &nparams) < 0)
         goto fail;
 
-    if (VIR_ALLOC_N(params, nparams) < 0)
-        goto fail;
+    params = g_new0(virNodeCPUStats, nparams);
 
     if (virHostCPUGetStatsLinux(cpustat, VIR_NODE_CPU_STATS_ALL_CPUS, params,
                                 &nparams) < 0)
index 76cc3d182f17929dfc9488596abc0865eab5a13a..9f6115f22672bc5fd8668975564ecd117b249fcf 100644 (file)
@@ -102,8 +102,7 @@ static int testMessageHeaderDecode(const void *args G_GNUC_UNUSED)
         return -1;
 
     msg->bufferLength = 4;
-    if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0)
-        goto cleanup;
+    msg->buffer = g_new0(char, msg->bufferLength);
     memcpy(msg->buffer, input_buf, msg->bufferLength);
 
     msg->header.prog = 0x11223344;
@@ -332,8 +331,7 @@ static int testMessagePayloadDecode(const void *args G_GNUC_UNUSED)
         return -1;
 
     msg->bufferLength = 4;
-    if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0)
-        goto cleanup;
+    msg->buffer = g_new0(char, msg->bufferLength);
     memcpy(msg->buffer, input_buffer, msg->bufferLength);
 
     if (virNetMessageDecodeLength(msg) < 0) {
index d6b461cbc8d6d6d4cdd6fb1d90fc109bdf42d288..5216b9842410c3827b37201c0f94959faf80dea0 100644 (file)
@@ -206,11 +206,7 @@ testSocketAccept(const void *opaque)
         if (virNetSocketNewListenUNIX(path, 0700, -1, getegid(), &usock) < 0)
             goto cleanup;
 
-        if (VIR_ALLOC_N(lsock, 1) < 0) {
-            virObjectUnref(usock);
-            goto cleanup;
-        }
-
+        lsock = g_new0(virNetSocketPtr, 1);
         lsock[0] = usock;
         nlsock = 1;
 
index e0a47718941df4828a1e99942b5f6b674bddbb7a..ce38571b0adb746714303e49d19d3028e347e463 100644 (file)
@@ -117,8 +117,7 @@ static void testTLSDerEncode(ASN1_TYPE src,
     size = 0;
     asn1_der_coding(src, src_name, NULL, &size, NULL);
 
-    if (VIR_ALLOC_N(data, size) < 0)
-        abort();
+    data = g_new0(char, size);
 
     asn1_der_coding(src, src_name, data, &size, NULL);
 
index b2ef57c3389efb55e9f02c54ddf33903c4eb07bb..73051906918216b5610c4a047848b50d24d0652a 100644 (file)
@@ -555,8 +555,7 @@ testVirStringListFreeCount(const void *opaque G_GNUC_UNUSED)
 {
     char **list;
 
-    if (VIR_ALLOC_N(list, 4) < 0)
-        return -1;
+    list = g_new0(char *, 4);
 
     list[0] = g_strdup("test1");
     list[2] = g_strdup("test2");
index 3ad66ccfa15c476f55aa6bb91cc7278247c637d9..ab1a834f1b7dced8f426d034dd69ec0c8ea715f2 100644 (file)
@@ -73,8 +73,7 @@ testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
     virDomainDefPtr def = NULL;
     char *replacedXML = NULL;
 
-    if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0)
-        goto fail;
+    gotxlcfgData = g_new0(char, wrote);
 
     conn = virGetConnect();
     if (!conn) goto fail;
index 43949fe3b535f49c6fc88c54b8faa2567906a117..8d6b2378fddeedd97302a829e9cf625cc811812c 100644 (file)
@@ -46,8 +46,7 @@ testCompareParseXML(const char *xmcfg, const char *xml)
     int wrote = 4096;
     virDomainDefPtr def = NULL;
 
-    if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
-        goto fail;
+    gotxmcfgData = g_new0(char, wrote);
 
     conn = virGetConnect();
     if (!conn) goto fail;