[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#386174: gcc-4.1: gcc sometimes doesn't recognize uninitialized variables

Package: gcc-4.1
Version: 4.1.1-10
Severity: normal

In the following program, gcc fails to recognize that "n" is
uninitialized, unless the "sscanf" line is commented out.  I expected
no change at all, since sscanf() is called after foo().  Since the
compiler is responsible for guaranteeing that the program runs as if
this order is true (even if it is not), I expect it to be aware of the
initialized state of the variables.

gcc-4.1 -std=gnu99 -W -Wall -O3 -g    ss.c   -o ss
ss.c: In function 'main':
ss.c:6: warning: 'n' is used uninitialized in this function

gcc-4.1 -DSS -std=gnu99 -W -Wall -O3 -g    ss.c   -o ss
[no warning]

#define _GNU_SOURCE
#include <stdio.h>

static void foo(size_t *n)
	printf("%d\n", *n);

int main()
	size_t n;
#ifdef	SS
	sscanf("1234", "%zd", &n);

	return 0;

Reply to: