Skip to content

Commit

Permalink
reiserfs: avoid uninitialized variable use
Browse files Browse the repository at this point in the history
I got this warning on an ARM64 allmodconfig build with gcc-5.3:

fs/reiserfs/ibalance.c: In function 'balance_internal':
fs/reiserfs/ibalance.c:1158:3: error: 'new_insert_key' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);

The warning is correct, in fact both new_insert_key and new_insert_ptr are
only updated inside of an if() block, but used at the end of the function.

Looking at how the balance_internal() function gets called, it is clear
that this is harmless because the caller never uses the updated arrays,
they are initialized from balance_leaf_new_nodes() and then passed into
balance_internal().

This has not changed at all since the start of the git history, but
apparently the warning has only recently appeared.

This modifies the function to only update the two argument variables when
the new_insert_key and new_insert_ptr have been updated, to get rid of the
warning.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnd Bergmann <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: Jan Kara <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
arndb authored and sfrothwell committed May 28, 2016
1 parent 40ed956 commit 5e6cc8e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/reiserfs/ibalance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,9 @@ int balance_internal(struct tree_balance *tb,
S_new);

/* S_new is released in unfix_nodes */

memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
insert_ptr[0] = new_insert_ptr;
}

n = B_NR_ITEMS(tbSh); /*number of items in S[h] */
Expand All @@ -1153,8 +1156,5 @@ int balance_internal(struct tree_balance *tb,
insert_ptr);
}

memcpy(new_insert_key_addr, &new_insert_key, KEY_SIZE);
insert_ptr[0] = new_insert_ptr;

return order;
}

0 comments on commit 5e6cc8e

Please sign in to comment.