All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [KJ] [PATCH] Fix gcc4 warning, idx may be used uninitialized
@ 2005-05-20 19:51 Jesse Millan
  2005-05-22 18:33 ` Jesse Millan
  0 siblings, 1 reply; 2+ messages in thread
From: Jesse Millan @ 2005-05-20 19:51 UTC (permalink / raw)
  To: kernel-janitors


So, the compiler should be able to tell that either one of the two cases
apply?

a: an assignment statement will be done on idx before its ever read

or

b: no assignment statement, control flow will never allow idx to be read

Alexey Dobriyan wrote:
> On Friday 20 May 2005 22:53, Jesse Millan wrote:
> 
>>This patch eliminates the warning that is generated when passing an
>>uninitialized variable to a function, and in that function it 'looks'
>>like you may read the contents.
>>
>>In this case, the address of a local variable 'idx' is passed to the
>>function bvec_alloc_bs(). Inside bvec_alloc_bs(), it is possible that
>>no value will be assigned to idx, in which case the function immediately
>>returns null and does not go on to read it. Human eyes can see that its
>>safe.
> 
> 
> I think this should go straight to http://gcc.gnu.org/bugzilla/enter_bug.cgi
> 

-- 
Jesse Millan
CNS Unix Team
Portland State University
Phone: (503) 725-9151
Mobile: (503) 453-0748
GPG key: www.system-calls.com/gpg.php

grep --recursive --ignore-case 'SHOULD WORK' /usr/src/linux/* | wc
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
http://lists.osdl.org/mailman/listinfo/kernel-janitors

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [KJ] [PATCH] Fix gcc4 warning, idx may be used uninitialized
  2005-05-20 19:51 [KJ] [PATCH] Fix gcc4 warning, idx may be used uninitialized Jesse Millan
@ 2005-05-22 18:33 ` Jesse Millan
  0 siblings, 0 replies; 2+ messages in thread
From: Jesse Millan @ 2005-05-22 18:33 UTC (permalink / raw)
  To: kernel-janitors


Its not easy to reproduce this warning in a simple program. And, I am
not sure that it is a bug on gcc4's part. It looks like gcc4 emits the
warning when it cannot prove beyond a shadow of doubt that the variable
is initialized before use.

In an effort to cut down on warnings, should these be fixed? It can go
either way, the compiler should be smart enough and maybe it will be
someday, or, do the initialization to get rid of a bunch of warnings.

Any feed back would be appreciated.

Arnd Bergmann wrote:
> On Freedag 20 Mai 2005 21:51, Jesse Millan wrote:
> 
>>So, the compiler should be able to tell that either one of the two cases
>>apply?
>>
>>a: an assignment statement will be done on idx before its ever read
>>
>>or
>>
>>b: no assignment statement, control flow will never allow idx to be read
> 
> 
> gcc is normally pretty good at detecting this. Since gcc-4.0, it 
> appears to do more checking inside inline functions, where older
> versions just assumed that a variable is initialized after a reference
> to it is passed to an inline function.
> 
> I'd suggest fixing the inline function to always do this instead of
> fixing the caller. After all, this needs to be fixed in the kernel,
> even if future gcc versions become smarter about it gcc-4.0 will
> continue to be used.
> 
> 	Arnd <><
> 
> --- a/fs/bio.c	2005-03-29 03:42:37 +02:00
> +++ b/fs/bio.c	2005-05-22 11:22:17 +02:00
> @@ -90,6 +90,7 @@
>  		case  65 ... 128: *idx = 4; break;
>  		case 129 ... BIO_MAX_PAGES: *idx = 5; break;
>  		default:
> +			*idx = 0;
>  			return NULL;
>  	}
>  	/*
> 

-- 
Jesse Millan
CNS Unix Team
Portland State University
Phone: (503) 725-9151
Mobile: (503) 453-0748
GPG key: www.system-calls.com/gpg.php

grep --recursive --ignore-case 'SHOULD WORK' /usr/src/linux/* | wc
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
http://lists.osdl.org/mailman/listinfo/kernel-janitors

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-05-22 18:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-20 19:51 [KJ] [PATCH] Fix gcc4 warning, idx may be used uninitialized Jesse Millan
2005-05-22 18:33 ` Jesse Millan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.