Flaw in method to detect uninitialized variables ?
Han Holl
jeholl@euronet.nl
Fri Feb 13 02:04:00 GMT 1998
void f(int a, const char *s)
{
int c, count = 0;
while (count < a && (c = *s++) != 0) {
if (c == 8)
break;
count++;
}
}
void g(int a, const char *s)
{
int c, count = 0;
while (count++ < a && (c = *s++) != 0) {
if (c == 8)
break;
}
}
/*
specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnulibc1/egcs-2.90.23/specs
gcc version egcs-2.90.23 980102 (egcs-1.0.1 release)
Compile with -c -O -Wuninitialized , and you get:
try7.C: In function `void g(int, const char *)':
try7.C:14: warning: `int c' might be used uninitialized in this function
Isn't that interesting ?
Regards,
Han Holl
*/
More information about the Gcc
mailing list