btrfs-progs: -Wshadow fixes
cover btrfs-progs: -Wshadow fixes
Since -Wshadow is enabled recently, there are two new warnings:
- @e from cmd_inspect_list_chunks()
- @csum from print_header_info()
This needs experimental features to be enabled
Just fix them all.
Qu Wenruo (2):
btrfs-progs: remove variable e from cmd_inspect_list_chunks()
btrfs-progs: fix a variable shadowing when enabling experimental
features
cmds/inspect.c | 4 +--- kernel-shared/print-tree.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-)
--
2.42.0
PATCH 1/2 btrfs-progs: remove variable e from cmd_inspect_list_chunks()
The variable @e is only utilized to record the errno from ioctl() call, and is only for the error message.
We can go with "%m" to replace the usage of variable @e, and remove the variable shadowing, as later we will declare a local variable @e with a different type.
--- cmds/inspect.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
cmds/inspect.c +1 -3
@@ -1026,7 +1026,6 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,int ret;int fd;int i; -int e;DIR *dirstream =NULL ;unsigned unit_mode;char *sortmode =NULL ;
@@ -1114,9 +1113,8 @@ static int cmd_inspect_list_chunks(const struct cmd_struct *cmd,while (1 ) { sk->nr_items =1 ; ret =ioctl (fd,BTRFS_IOC_TREE_SEARCH , &args); - e = errno;if (ret <0 ) { -error ("cannot perform the search: %s" ,strerror (e)); +error ("cannot perform the search: %m" );return 1 ; }if (sk->nr_items ==0 )
Signature · 1 line
2.42.0
PATCH 2/2 btrfs-progs: fix a variable shadowing when enabling experimental features
In reply to Qu WenruoThere is another variable shadowing problem which can only be exposed if experimental features are enabled.
Inside the branch of BTRFS_PRINT_TREE_CSUM_HEADERS, we declare another local variable @csum, shadowing the @csum of print_header_info(), which is only declared when experimental features are enabled.
Just rename the @csum to @tree_csum to avoid the problem.
--- kernel-shared/print-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel-shared/print-tree.c +2 -2
@@ -1271,12 +1271,12 @@ static void print_header_info(struct extent_buffer *eb, unsigned int mode)printf ("\n" );if (fs_info && (mode &BTRFS_PRINT_TREE_CSUM_HEADERS )) {char *tmp = csum_str; -u8 *csum = (u8 *)(eb->data + offsetof(struct btrfs_header , csum)); +u8 *tree_csum = (u8 *)(eb->data + offsetof(struct btrfs_header , csum));strcpy (csum_str," csum 0x" ); tmp = csum_str +strlen (csum_str);for (i =0 ; i < csum_size; i++) { -sprintf (tmp,"%02x" , csum[i]); +sprintf (tmp,"%02x" , tree_csum[i]); tmp++; tmp++; }
Signature · 1 line
2.42.0
Quoted 6 lines · Qu Wenruo
Since -Wshadow is enabled recently, there are two new warnings:
- @e from
cmd_inspect_list_chunks()
- @csum fromprint_header_info()
This needs experimental features to be enabled
Quoted 6 lines
Just fix them all.
Qu Wenruo (2):
btrfs-progs: remove variable e fromcmd_inspect_list_chunks()
btrfs-progs: fix a variable shadowing when enabling experimental
features
Added to devel, thanks.