]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: avoid potential null pointer dereference by GCC 10
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Thu, 13 Aug 2020 14:03:45 +0000 (16:03 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 17 Aug 2020 06:25:28 +0000 (08:25 +0200)
GCC 10 complains about "arg" possibly being a NULL dereference.
Even though it might be a false positive, we can easily avoid it.

Avoiding
 ../tools/vsh.c: In function ‘vshCommandOptStringReq’:
 ../tools/vsh.c:1034:19: error: potential null pointer dereference [-Werror=null-dereference]
  1034 |     else if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK))
       |                ~~~^~~~~~

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
tools/vsh.c

index 5e2e3ac2190be965cd310274b3739dfabc8b082b..11f493f969e8eb499d27181c9614fe3ee422b157 100644 (file)
@@ -1031,7 +1031,7 @@ vshCommandOptStringReq(vshControl *ctl,
     /* this should not be propagated here, just to be sure */
     if (ret == -1)
         error = N_("Mandatory option not present");
-    else if (!*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK))
+    else if (arg && !*arg->data && !(arg->def->flags & VSH_OFLAG_EMPTY_OK))
         error = N_("Option argument is empty");
 
     if (error) {