]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: Fix logic to not have possible NULL deref
authorJohn Ferlan <jferlan@redhat.com>
Sun, 3 Nov 2019 12:55:21 +0000 (07:55 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 6 Nov 2019 16:27:12 +0000 (11:27 -0500)
It's possible that virBitmapNewString returns NULL with an error
string (and not an allocation failure that would abort); however, if
virBitmapToString is called with a NULL @bitmap, then it will fail
in an ugly manner. So rather than have if (!map && !str) logic, split
the checks for each variable.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tests/virbitmaptest.c

index 545e9272df599c9c7618db1cb8357390a2358dca..2808d9c88072c956c1d55e16e42734c99f0dd31f 100644 (file)
@@ -682,9 +682,11 @@ test13(const void *opaque G_GNUC_UNUSED)
 
     for (i = 0; i < G_N_ELEMENTS(strings); i++) {
         map = virBitmapNewString(strings[i]);
-        str = virBitmapToString(map, false, true);
+        if (!map)
+            goto cleanup;
 
-        if (!map || !str)
+        str = virBitmapToString(map, false, true);
+        if (!str)
             goto cleanup;
 
         if (STRNEQ(strings[i], str)) {