[PATCH] mkfs.nilfs2: fix gcc warning "array subscript is above array bounds"

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

 



Recent gcc compiler (e.g. gcc version 4.9.1) gives a false positive
warning during the build of mkfs.nilfs2:

 mkfs.c: In function 'main':
 mkfs.c:540:47: warning: array subscript is above array bounds [-Warray-bounds]
    struct nilfs_segment_info *si = &di->seginfo[i];
                                               ^
 mkfs.c:540:47: warning: array subscript is above array bounds [-Warray-bounds]
 mkfs.c:540:47: warning: array subscript is above array bounds [-Warray-bounds]
 mkfs.c:540:47: warning: array subscript is above array bounds [-Warray-bounds]

This fixes the issue.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@xxxxxxxxxxxxx>
---
 sbin/mkfs/mkfs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sbin/mkfs/mkfs.c b/sbin/mkfs/mkfs.c
index c7e18c6..f5f7dbb 100644
--- a/sbin/mkfs/mkfs.c
+++ b/sbin/mkfs/mkfs.c
@@ -532,12 +532,12 @@ static struct nilfs_segment_info *new_segment(struct nilfs_disk_info *di)
 
 static void fix_disk_layout(struct nilfs_disk_info *di)
 {
+	struct nilfs_segment_info *si;
 	int i, j;
 
 	di->nblocks_used = 0;
 	di->nblocks_to_write = di->first_segment_block;
-	for (i = 0; i < di->nseginfo; i++) {
-		struct nilfs_segment_info *si = &di->seginfo[i];
+	for (i = 0, si = di->seginfo; i < di->nseginfo; i++, si++) {
 		blocknr_t blocknr = si->start + si->nblk_sum;
 
 		si->nblocks += si->nblk_sum + 1 /* summary and super root */;
-- 
1.7.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux BTRFS]     [Linux CIFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux