Skip to contentSkip to conversation

fs: tree-checker: fix missing brace warning for old compilers

PATCH In review Pujin Shi 3 participants 3 messages Oct 3, 2020 Btrfs file system

lore
Share & tools
lore

Pujin Shi

author
#0 lore raw

PATCH 1/1 fs: tree-checker: fix missing brace warning for old compilers

For older versions of gcc, the array = {0}; will cause warnings:

fs/btrfs/tree-checker.c: In function 'check_root_item':
fs/btrfs/tree-checker.c:1038:9: warning: missing braces around initializer [-Wmissing-braces]

  struct btrfs_root_item ri = { 0 };
         ^

fs/btrfs/tree-checker.c:1038:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

1 warnings generated

Fixes 443b313c7ff8 ("btrfs: tree-checker: fix false alert caused by legacy btrfs root item")
---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index f0ffd5ee77bd..5028b3af308c 100644
@@ -1035,7 +1035,7 @@ static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key,
 			   int slot)
 {
 	struct btrfs_fs_info *fs_info = leaf->fs_info;
-	struct btrfs_root_item ri = { 0 };
+	struct btrfs_root_item ri = {};
 	const u64 valid_root_flags = BTRFS_ROOT_SUBVOL_RDONLY |
 				     BTRFS_ROOT_SUBVOL_DEAD;
 	int ret;
Signature · 1 line
2.18.1
#1 lore raw
Quoted 2 lines · Pujin Shi

For older versions of gcc, the array = {0}; will cause warnings:

So what's the version number of the gcc? "struct foo = { 0 }" should be correct.

May be the compiler issue[1] related?

1: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119

Quoted 28 lines

fs/btrfs/tree-checker.c: In function 'check_root_item':
fs/btrfs/tree-checker.c:1038:9: warning: missing braces around initializer [-Wmissing-braces]

  struct btrfs_root_item ri = { 0 };
         ^

fs/btrfs/tree-checker.c:1038:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

1 warnings generated

Fixes 443b313c7ff8 ("btrfs: tree-checker: fix false alert caused by legacy btrfs root item")
---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index f0ffd5ee77bd..5028b3af308c 100644
@@ -1035,7 +1035,7 @@ static int check_root_item(struct 
 extent_buffer *leaf, struct btrfs_key *key,
 			   int slot)
 {
 	struct btrfs_fs_info *fs_info = leaf->fs_info;
-	struct btrfs_root_item ri = { 0 };
+	struct btrfs_root_item ri = {};
 	const u64 valid_root_flags = BTRFS_ROOT_SUBVOL_RDONLY |
 				     BTRFS_ROOT_SUBVOL_DEAD;

int ret;

#2 lore raw
In reply to Pujin Shi
Quoted 4 lines · Pujin Shi

For older versions of gcc, the array = {0}; will cause warnings:

fs/btrfs/tree-checker.c: In function 'check_root_item':
fs/btrfs/tree-checker.c:1038:9: warning: missing braces around initializer [-Wmissing-braces]

Quoted 8 lines
  struct btrfs_root_item ri = { 0 };
         ^

fs/btrfs/tree-checker.c:1038:9: warning: (near initialization for 'ri.inode') [-Wmissing-braces]

1 warnings generated

Fixes 443b313c7ff8 ("btrfs: tree-checker: fix false alert caused by legacy btrfs root item")

This is a compiler artifact, please see:
http://www.ex-parrot.com/~chris/random/initialise.html

ALso having an empty initialization list like = {} while valid for gcc is actually invalid according to the official standard. Check ISO C Standard section 6.7.9 for the correct syntax of initializer-list.

IOW - NAK.

Quoted 18 lines
---
 fs/btrfs/tree-checker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-checker.c +1 -1
index f0ffd5ee77bd..5028b3af308c 100644
@@ -1035,7 +1035,7 @@ static int check_root_item(struct extent_buffer *leaf, struct btrfs_key *key,
 			   int slot)
 {
 	struct btrfs_fs_info *fs_info = leaf->fs_info;
-	struct btrfs_root_item ri = { 0 };
+	struct btrfs_root_item ri = {};
 	const u64 valid_root_flags = BTRFS_ROOT_SUBVOL_RDONLY |
 				     BTRFS_ROOT_SUBVOL_DEAD;
 	int ret;