]> xenbits.xensource.com Git - libvirt.git/commitdiff
vsh: Properly initialize res
authorJohn Ferlan <jferlan@redhat.com>
Mon, 18 Jul 2016 18:37:38 +0000 (14:37 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 19 Jul 2016 11:51:10 +0000 (07:51 -0400)
The 'res' variable was only being initialized to NULL in the
if (!state) path; however, that path never used res and evenutally
res is assigned one of two results based on a pair of if then else if
conditions. If for some reason neither of those paths was taken and
the (!state) path wasn't taken, then 'res' would be indeterminate.

Found by Coverity, probably a false positive based on code paths, but
better safe than sorry for the future.

Signed-off-by: John Ferlan <jferlan@redhat.com>
tools/vsh.c

index 68f77859fb2d68aa5eb86dd86cafb1480492f5aa..9ac4f21ce9160907e8865eb3391b385e2fdd7cc9 100644 (file)
@@ -2636,7 +2636,8 @@ vshReadlineParse(const char *text, int state)
     vshCommandToken tk;
     static const vshCmdDef *cmd;
     const vshCmdOptDef *opt;
-    char *tkdata, *optstr, *const_tkdata, *res;
+    char *tkdata, *optstr, *const_tkdata;
+    char *res = NULL;
     static char *ctext, *sanitized_text;
     static uint64_t const_opts_need_arg, const_opts_required, const_opts_seen;
     uint64_t opts_need_arg, opts_required, opts_seen;
@@ -2656,7 +2657,6 @@ vshReadlineParse(const char *text, int state)
         tkdata = NULL;
         sanitized_text = NULL;
         optstr = NULL;
-        res = NULL;
 
         /* Sanitize/de-quote the autocomplete text */
         tk = sanitizer.getNextArg(NULL, &sanitizer, &sanitized_text, false);