fs/ext2/ext2fs.c: fix warning
PATCH 1/1 fs/ext2/ext2fs.c: fix warning
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.
--- fs/ext2/ext2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext2/ext2fs.c +1 -1
@@ -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 )) {
Signature · 1 line
1.7.10
PATCH 1/1 fs/ext2/ext2fs.c: fix warning
Quoted 21 lines · Andreas Bie?mann
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 <[email protected]>cc Jason Cooper <[email protected]>cc Eric Nelson <[email protected]>cc Thierry Reding <[email protected]>--- fs/ext2/ext2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ext2/ext2fs.c +0
-0
fs/ext2/ext2fs.c int ext2fs_read_file · line 446
Quoted 8 lines
fs/ext2/ext2fs.c +1
-1@@ -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>
PATCH 1/1 fs/ext2/ext2fs.c: fix warning
Quoted 27 lines · Thierry Reding
Quoted 26 lines · Andreas Bie?mann
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 <[email protected]>cc Jason Cooper <[email protected]>cc Eric Nelson <[email protected]>cc Thierry Reding <[email protected]>--- fs/ext2/ext2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ext2/ext2fs.c +1
-1@@ -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;
Quoted 8 lines
fs/ext2/ext2fs.c int ext2fs_read_file · line 446
Quoted 3 lines
fs/ext2/ext2fs.c +0
-0while (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.