http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52078

             Bug #: 52078
           Summary: Bogus may be used uninitialized warning
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: rmansfi...@qnx.com
              Host: x86_64-linux-gnu
            Target: x86_64-linux-gnu
             Build: x86_64-linux-gnu


gcc version 4.7.0 20120201 (experimental) [trunk revision 183790] (GCC) 

Testcase:

#include <string.h>

int
foo (char *nname, char *oname)
{
  int cmp;

  while (nname != oname && (cmp = strcmp (nname, oname)) < 0)
    {
      break;
    }
  if (nname == oname || cmp == 0)
    {
      return 1;
    }
  else
    {
      return 0;
    }
}


$ ./xgcc -B. -O2 -Wall ~/init.c -c 
/home/ryan/init.c: In function 'foo':
/home/ryan/init.c:12:29: warning: 'cmp' may be used uninitialized in this
function [-Wmaybe-uninitialized]

Since both && and || operators guarantee left-to-right evaluation, in the case
where nname == oname, strcmp is never called but in the (name == oname || cmp
== 0) expression, nname == oname and the second operand is not evaluated so cmp
is never used uninitialized.

Reply via email to