[PATCH 2/3] tools: avoid potential null pointer dereference by GCC 10

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
Reviewed-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx>
---
 tools/vsh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 5e2e3ac219..11f493f969 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -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) {
-- 
2.25.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux