All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] fs/ext2/ext2fs.c: fix warning
@ 2012-06-27 11:47 Andreas Bießmann
  2012-06-27 11:55 ` Thierry Reding
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Bießmann @ 2012-06-27 11:47 UTC (permalink / raw)
  To: u-boot

This patch fixes following warning:
---8<---
ext2fs.c: In function 'ext2fs_read_file':
ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this function [-Wuninitialized]
--->8---

The warning was introduced in 436da3cd233e7166b5ce9293dbd28092cf37bcc9.

Signed-off-by: Andreas Bie?mann <andreas.devel@googlemail.com>
cc: Jason Cooper <u-boot@lakedaemon.net>
cc: Eric Nelson <eric.nelson@boundarydevices.com>
cc: Thierry Reding <thierry.reding@avionic-design.de>
---
 fs/ext2/ext2fs.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c
index f1fce48..40b6e6f 100644
--- a/fs/ext2/ext2fs.c
+++ b/fs/ext2/ext2fs.c
@@ -440,7 +440,7 @@ int ext2fs_read_file
 		/* grab middle blocks in one go */
 		if (i != pos / blocksize && i != blockcnt - 1 && blockcnt > 3) {
 			int oldblk = blknr;
-			int blocknxt;
+			int blocknxt = blknr;
 			while (i < blockcnt - 1) {
 				blocknxt = ext2fs_read_block(node, i + 1);
 				if (blocknxt == (oldblk + 1)) {
-- 
1.7.10

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

* [U-Boot] [PATCH] fs/ext2/ext2fs.c: fix warning
  2012-06-27 11:47 [U-Boot] [PATCH] fs/ext2/ext2fs.c: fix warning Andreas Bießmann
@ 2012-06-27 11:55 ` Thierry Reding
  2012-07-06 14:09   ` Jason Cooper
  0 siblings, 1 reply; 3+ messages in thread
From: Thierry Reding @ 2012-06-27 11:55 UTC (permalink / raw)
  To: u-boot

On Wed, Jun 27, 2012 at 01:47:51PM +0200, Andreas Bie?mann wrote:
> This patch fixes following warning:
> ---8<---
> ext2fs.c: In function 'ext2fs_read_file':
> ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this function [-Wuninitialized]
> --->8---
> 
> The warning was introduced in 436da3cd233e7166b5ce9293dbd28092cf37bcc9.
> 
> Signed-off-by: Andreas Bie?mann <andreas.devel@googlemail.com>
> cc: Jason Cooper <u-boot@lakedaemon.net>
> cc: Eric Nelson <eric.nelson@boundarydevices.com>
> cc: Thierry Reding <thierry.reding@avionic-design.de>
> ---
>  fs/ext2/ext2fs.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c
> index f1fce48..40b6e6f 100644
> --- a/fs/ext2/ext2fs.c
> +++ b/fs/ext2/ext2fs.c
> @@ -440,7 +440,7 @@ int ext2fs_read_file
>  		/* grab middle blocks in one go */
>  		if (i != pos / blocksize && i != blockcnt - 1 && blockcnt > 3) {
>  			int oldblk = blknr;
> -			int blocknxt;
> +			int blocknxt = blknr;
>  			while (i < blockcnt - 1) {
>  				blocknxt = ext2fs_read_block(node, i + 1);
>  				if (blocknxt == (oldblk + 1)) {

This doesn't look quite right. The warning should go away as well if you
change the "i != blockcnt - 1" to "i < blockcnt - 1" in the condition
above. I think that'd be more appropriate, but perhaps Jason is better
qualified to comment.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120627/ce9d649f/attachment.pgp>

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

* [U-Boot] [PATCH] fs/ext2/ext2fs.c: fix warning
  2012-06-27 11:55 ` Thierry Reding
@ 2012-07-06 14:09   ` Jason Cooper
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Cooper @ 2012-07-06 14:09 UTC (permalink / raw)
  To: u-boot

On Wed, Jun 27, 2012 at 01:55:39PM +0200, Thierry Reding wrote:
> On Wed, Jun 27, 2012 at 01:47:51PM +0200, Andreas Bie?mann wrote:
> > This patch fixes following warning:
> > ---8<---
> > ext2fs.c: In function 'ext2fs_read_file':
> > ext2fs.c:458:19: warning: 'blocknxt' may be used uninitialized in this function [-Wuninitialized]
> > --->8---
> > 
> > The warning was introduced in 436da3cd233e7166b5ce9293dbd28092cf37bcc9.
> > 
> > Signed-off-by: Andreas Bie?mann <andreas.devel@googlemail.com>
> > cc: Jason Cooper <u-boot@lakedaemon.net>
> > cc: Eric Nelson <eric.nelson@boundarydevices.com>
> > cc: Thierry Reding <thierry.reding@avionic-design.de>
> > ---
> >  fs/ext2/ext2fs.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/fs/ext2/ext2fs.c b/fs/ext2/ext2fs.c
> > index f1fce48..40b6e6f 100644
> > --- a/fs/ext2/ext2fs.c
> > +++ b/fs/ext2/ext2fs.c
> > @@ -440,7 +440,7 @@ int ext2fs_read_file
> >  		/* grab middle blocks in one go */
> >  		if (i != pos / blocksize && i != blockcnt - 1 && blockcnt > 3) {
> >  			int oldblk = blknr;
> > -			int blocknxt;
> > +			int blocknxt = blknr;
> >  			while (i < blockcnt - 1) {
> >  				blocknxt = ext2fs_read_block(node, i + 1);
> >  				if (blocknxt == (oldblk + 1)) {
> 
> This doesn't look quite right. The warning should go away as well if you
> change the "i != blockcnt - 1" to "i < blockcnt - 1" in the condition
> above. I think that'd be more appropriate, but perhaps Jason is better
> qualified to comment.

I agree.  The compiler is rightfully complaining because there is a
scenario where blockcnt > 3 and i = blockcnt - 1.  In this case, we
would decend into the if() block, but not the while() block.  blocknxt
is used after the while() block, which would then be uninitialized.

By fixing the logic in the if() block, this can't happen.  I've Ack'd
Kim's version.

Thanks for testing, Thierry.

thx,

Jason.

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

end of thread, other threads:[~2012-07-06 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-27 11:47 [U-Boot] [PATCH] fs/ext2/ext2fs.c: fix warning Andreas Bießmann
2012-06-27 11:55 ` Thierry Reding
2012-07-06 14:09   ` Jason Cooper

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.