]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: pcivpdtest: check return value of virCreateAnonymousFile
authorJán Tomko <jtomko@redhat.com>
Tue, 23 Nov 2021 14:05:43 +0000 (15:05 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 23 Nov 2021 15:59:36 +0000 (16:59 +0100)
Fixes: 59c1bc3a0e25e6d725db41990f11e0b53137115d
Fixes: 43820e4b8037680ec451761216750c6b139db67a
Fixes: 600f580d623ae4077ddeb6c7cb24f8a315a7c73b
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Kristína Hanicová <khanicov@redhat.com>
tests/virpcivpdtest.c

index 284350fe2904d37fc43d21444cbcca2a587ad9bb..a6bf46b103a559dd6f4ebf02f2080fb226f8aac6 100644 (file)
@@ -445,7 +445,8 @@ testVirPCIVPDReadVPDBytes(const void *opaque G_GNUC_UNUSED)
     dataLen = G_N_ELEMENTS(fullVPDExample) - 2;
     buf = g_malloc0(dataLen);
 
-    fd = virCreateAnonymousFile(fullVPDExample, dataLen);
+    if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0)
+        return -1;
 
     readBytes = virPCIVPDReadVPDBytes(fd, buf, dataLen, 0, &csum);
 
@@ -481,7 +482,9 @@ testVirPCIVPDParseVPDStringResource(const void *opaque G_GNUC_UNUSED)
     };
 
     dataLen = G_N_ELEMENTS(stringResExample);
-    fd = virCreateAnonymousFile(stringResExample, dataLen);
+    if ((fd = virCreateAnonymousFile(stringResExample, dataLen)) < 0)
+        return -1;
+
     result = virPCIVPDParseVPDLargeResourceString(fd, 0, dataLen, &csum, res);
     VIR_FORCE_CLOSE(fd);
 
@@ -551,7 +554,9 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNUSED)
     };
 
     dataLen = G_N_ELEMENTS(fullVPDExample);
-    fd = virCreateAnonymousFile(fullVPDExample, dataLen);
+    if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0)
+        return -1;
+
     res = virPCIVPDParse(fd);
     VIR_FORCE_CLOSE(fd);
 
@@ -619,7 +624,9 @@ testVirPCIVPDParseZeroLengthRW(const void *opaque G_GNUC_UNUSED)
     };
 
     dataLen = G_N_ELEMENTS(fullVPDExample);
-    fd = virCreateAnonymousFile(fullVPDExample, dataLen);
+    if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0)
+        return -1;
+
     res = virPCIVPDParse(fd);
     VIR_FORCE_CLOSE(fd);
 
@@ -669,7 +676,9 @@ testVirPCIVPDParseNoRW(const void *opaque G_GNUC_UNUSED)
     };
 
     dataLen = G_N_ELEMENTS(fullVPDExample);
-    fd = virCreateAnonymousFile(fullVPDExample, dataLen);
+    if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0)
+        return -1;
+
     res = virPCIVPDParse(fd);
     VIR_FORCE_CLOSE(fd);
 
@@ -722,7 +731,9 @@ testVirPCIVPDParseFullVPDSkipInvalidKeywords(const void *opaque G_GNUC_UNUSED)
     };
 
     dataLen = G_N_ELEMENTS(fullVPDExample);
-    fd = virCreateAnonymousFile(fullVPDExample, dataLen);
+    if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0)
+        return -1;
+
     res = virPCIVPDParse(fd);
     VIR_FORCE_CLOSE(fd);
 
@@ -775,7 +786,9 @@ testVirPCIVPDParseFullVPDSkipInvalidValues(const void *opaque G_GNUC_UNUSED)
     };
 
     dataLen = G_N_ELEMENTS(fullVPDExample);
-    fd = virCreateAnonymousFile(fullVPDExample, dataLen);
+    if ((fd = virCreateAnonymousFile(fullVPDExample, dataLen)) < 0)
+        return -1;
+
     res = virPCIVPDParse(fd);
     VIR_FORCE_CLOSE(fd);
 
@@ -951,7 +964,8 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_GNUC_UNUSED)
         g_autoptr(virPCIVPDResource) res = NULL; \
         const uint8_t testCase[] = { invalidVPD }; \
         dataLen = G_N_ELEMENTS(testCase); \
-        fd = virCreateAnonymousFile(testCase, dataLen); \
+        if ((fd = virCreateAnonymousFile(testCase, dataLen)) < 0) \
+            return -1; \
         if ((res = virPCIVPDParse(fd))) { \
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
                     "Successfully parsed an invalid VPD - this is not expected"); \