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]
Other format: [Raw text]

Re: Uninitialized use warning message


Kean Johnston wrote:
> Hello everyone,
> 
> There is a warning message I would dearly love to see improved
> a little. Its the one where you use a variable without it being
> initialized first:
> 
>   foo.c:123: warning: `foo' might be used unitialized in this function
> 
> Obviously, there was some code somewhere that used variable
> `foo' to trigger the warning. What I would dearly love to see
> is the warning message be a bit more informative, along the
> lines of:
> 
>   foo.c:123: warning: `foo' might be used unitialized in this function
>   foo.c:234: warning: possible use of unitialized `foo'
>   foo.c:345: warning: possible use of unitialized `foo'
> 
> You get the idea. Does anyone else think this would be useful?
> Do we even have sufficient data available to be able to produce
> such warnings? I figured I'd ask first before diving into the code.

Well, this is not this simple. It is usually easy for me to find where
it is used (possibly uninitialised). The harder part is finding the
control path that leads there without initialisation.

A common situation would be:

	if (condition) {
		flag = 1
		msg = "Hello World";
	} else
		flag = 0;			[1]
	...
	if (flag)
		printf ("I say, %s\n", msg);	[2]

Point [1] is where I "fail" to init 'msg', point [2] is where I
use it. I know that the program is safe, and if the flow analysis
can relate 'flag' and 'msg' then the warning would go away.

Which one would we want listed in the proposed new warning, 1 or 2?
Naturally, there can be multiple 1s and 2s for the same variable.

-- 
Eyal Lebedinsky (eyal@eyal.emu.id.au) <http://samba.org/eyal/>
	attach .zip as .dat


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