[Toybox] warning: char *s is never used uninitialized.

Rob Landley rob at landley.net
Mon Dec 23 21:36:02 PST 2019


Right now toys/pending/sh.c has two legitimate "unused variable" warnings
(because commented out unfinished code block, it's very much a work in
progress), but this:

toys/pending/sh.c: In function 'run_command.constprop':
toys/pending/sh.c:596:5: warning: 's' may be used uninitialized in this function
[-Wmaybe-uninitialized]
     syntax_err("bad %s", s);
     ^~~~~~~~~~~~~~~~~~~~~~~
toys/pending/sh.c:442:9: note: 's' was declared here
   char *s, *ss, *sss, *cv = 0;

Ummm... how? The code there boils down to:

  char *s;

  if (envlen>=arg->c) return 0;
  for (j = envlen; j<arg->c; j++) {
    s = arg->v[j];
    stuff();
  }
  if (j != arg->c) syntax_err("bad %s", s);

If we didn't go into the loop at least once, we don't call syntax_err(). If it's
>= the limit we returned early, if it's less we went into the loop at least once.

So no matter what value of envlen and arg->c are passed in, HOW can this be used
uninitialized? (Anybody else spot it?)

Rob



More information about the Toybox mailing list