diff mbox

btrfs-progs: fix uninitialized warining in btrfs_calc_stripe_index

Message ID 1412209921-21002-1-git-send-email-anand.jain@oracle.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Anand Jain Oct. 2, 2014, 12:32 a.m. UTC
chunk-recover.c: In function ‘btrfs_calc_stripe_index’:
chunk-recover.c:1481: warning: ‘index’ may be used uninitialized in this function

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 chunk-recover.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba Oct. 6, 2014, 5:19 p.m. UTC | #1
On Thu, Oct 02, 2014 at 08:32:01AM +0800, Anand Jain wrote:
> chunk-recover.c: In function ‘btrfs_calc_stripe_index’:
> chunk-recover.c:1481: warning: ‘index’ may be used uninitialized in this function
> --- a/chunk-recover.c
> +++ b/chunk-recover.c
> @@ -1478,7 +1478,7 @@ static int btrfs_calc_stripe_index(struct chunk_record *chunk, u64 logical)
>  	u64 offset = logical - chunk->offset;
>  	int stripe_nr;
>  	int nr_data_stripes;
> -	int index;
> +	int index = 0;
>  
>  	stripe_nr = offset / chunk->stripe_len;
>  	if (chunk->type_flags & BTRFS_BLOCK_GROUP_RAID0) {

The catch-all branch does BUG_ON so the compiler probably misses that
for some reason, otherwise the index value is always defined. It would
be better to replace the BUG_ON with "return -1" and handle the error in
the callers.

The BUG_ON happens if there's an unknown block group type, these are
well known and any error here means there's a corruption or unsupported
type. Both condition could be handled in a better way.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/chunk-recover.c b/chunk-recover.c
index 209d7a7..5daffe3 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1478,7 +1478,7 @@  static int btrfs_calc_stripe_index(struct chunk_record *chunk, u64 logical)
 	u64 offset = logical - chunk->offset;
 	int stripe_nr;
 	int nr_data_stripes;
-	int index;
+	int index = 0;
 
 	stripe_nr = offset / chunk->stripe_len;
 	if (chunk->type_flags & BTRFS_BLOCK_GROUP_RAID0) {