From 36128dff44036d8ea506f70b960f0d1f65b9c420 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 18 Nov 2019 14:30:49 +0800 Subject: [PATCH] btrfs-progs: check/lowmem: Fix a false alert on uninitialized value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [BUG] When compiling the devel branch with commit fb8f05e40b458 ("btrfs-progs: check: Make repair_imode_common() handle inodes in subvolume trees"), the following warning will be reported: check/mode-common.c: In function ‘detect_imode’: check/mode-common.c|1071 col 23| warning: ‘imode’ may be used uninitialized in this function [-Wmaybe-uninitialized] 1071 | *imode_ret = (imode | 0700); | ~~~~~~~^~~~~~~ This only occurs for regular build. If compiled with D=1, the warning just disappears. [CAUSE] Looks like a bug in gcc optimization. The code will only set @imode_ret when @found is true. And for every "found = true" assignment we have assigned @imode. So this is just a false alert. [FIX] I hope I can fix the problem of GCC, but obviously I can't (at least for now). So let's assign an initial value 0 to @imode to suppress the false alert. Reviewed-by: Nikolay Borisov Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- check/mode-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/mode-common.c b/check/mode-common.c index 10ad6d22..9e81082b 100644 --- a/check/mode-common.c +++ b/check/mode-common.c @@ -972,7 +972,7 @@ int detect_imode(struct btrfs_root *root, struct btrfs_path *path, struct btrfs_inode_item iitem; bool found = false; u64 ino; - u32 imode; + u32 imode = 0; int ret = 0; btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);