This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Flaw in method to detect uninitialized variables ?



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

*/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]