Skip to contentSkip to conversation

fs/gfs2/dir.c:gfs2_dir_write_data(): don't use an uninitialized variable

PATCH In review Adrian Bunk 2 participants 2 messages Oct 19, 2006 GFS2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/gfs2/dir.c:gfs2_dir_write_data(): don't use an uninitialized variable

In the "if (extlen)" case, "new" might be used uninitialized.

Looking at the code, it should be initialized to 0.

Spotted by the Coverity checker.

fs/gfs2/dir.c renamed from fs/gfs2/dir.c.old +1 -1
@@ -169,37 +169,37 @@ static int gfs2_dir_write_data(struct gf
 		return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset,
 					      size);
 
 	if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip)))
 		return -EINVAL;
 
 	if (gfs2_is_stuffed(ip)) {
 		error = gfs2_unstuff_dinode(ip, NULL);
 		if (error)
 			return error;
 	}
 
 	lblock = offset;
 	o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header);
 
 	while (copied < size) {
 		unsigned int amount;
 		struct buffer_head *bh;
-		int new;
+		int new = 0;
 
 		amount = size - copied;
 		if (amount > sdp->sd_sb.sb_bsize - o)
 			amount = sdp->sd_sb.sb_bsize - o;
 
 		if (!extlen) {
 			new = 1;
 			error = gfs2_extent_map(&ip->i_inode, lblock, &new,
 						&dblock, &extlen);
 			if (error)
 				goto fail;
 			error = -EIO;
 			if (gfs2_assert_withdraw(sdp, dblock))
 				goto fail;
 		}
 
 		if (amount == sdp->sd_jbsize || new)
 			error = gfs2_dir_get_new_buffer(ip, dblock, &bh);
#1 lore raw

Hi,

All three patches are now in the GFS2 git tree. Thanks,

Steve.

Quoted 50 lines · Adrian Bunk

In the "if (extlen)" case, "new" might be used uninitialized.

Looking at the code, it should be initialized to 0.

Spotted by the Coverity checker.

fs/gfs2/dir.c renamed from fs/gfs2/dir.c.old +1 -1
@@ -169,37 +169,37 @@ static int gfs2_dir_write_data(struct gf
 		return gfs2_dir_write_stuffed(ip, buf, (unsigned int)offset,
 					      size);
 
 	if (gfs2_assert_warn(sdp, gfs2_is_jdata(ip)))
 		return -EINVAL;
 
 	if (gfs2_is_stuffed(ip)) {
 		error = gfs2_unstuff_dinode(ip, NULL);
 		if (error)
 			return error;
 	}
 
 	lblock = offset;
 	o = do_div(lblock, sdp->sd_jbsize) + sizeof(struct gfs2_meta_header);
 
 	while (copied < size) {
 		unsigned int amount;
 		struct buffer_head *bh;
-		int new;
+		int new = 0;
 
 		amount = size - copied;
 		if (amount > sdp->sd_sb.sb_bsize - o)
 			amount = sdp->sd_sb.sb_bsize - o;
 
 		if (!extlen) {
 			new = 1;
 			error = gfs2_extent_map(&ip->i_inode, lblock, &new,
 						&dblock, &extlen);
 			if (error)
 				goto fail;
 			error = -EIO;
 			if (gfs2_assert_withdraw(sdp, dblock))
 				goto fail;
 		}
 
 		if (amount == sdp->sd_jbsize || new)
 			error = gfs2_dir_get_new_buffer(ip, dblock, &bh);