]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircapstest: Avoid (im)possible strcmp call with NULL argument
authorJiri Denemark <jdenemar@redhat.com>
Mon, 13 Nov 2017 21:22:07 +0000 (22:22 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Tue, 14 Nov 2017 13:45:19 +0000 (14:45 +0100)
Some compilers may get confused and decide we are calling strcmp with
NULL argument from test_virCapsDomainDataLookupLXC. Although this does
not really happen since the call is guarded with
(data->machinetype != expect_machinetype), using STRNEQ_NULLABLE is
easier to understand, less fragile, and doing so makes sure strcmp is
never called with NULL argument.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
tests/vircapstest.c

index 95829133d051fd12b5adf5ce707dc6b78d720266..05ec802f35a2a281f18ddf6e568b29ad1b381d75 100644 (file)
@@ -188,11 +188,10 @@ doCapsCompare(virCapsPtr caps,
         goto error;
     }
 
-    if (data->machinetype != expect_machinetype &&
-        STRNEQ(data->machinetype, expect_machinetype)) {
+    if (STRNEQ_NULLABLE(data->machinetype, expect_machinetype)) {
         fprintf(stderr, "data->machinetype=%s doesn't match "
                 "expect_machinetype=%s\n",
-                data->machinetype, expect_machinetype);
+                NULLSTR(data->machinetype), NULLSTR(expect_machinetype));
         goto error;
     }