selftests/bpf: fix a compilation warning
Subsystems (3)
PATCH 1/1 selftests/bpf: fix a compilation warning
The following warning is triggered when I used clang compiler to build the selftest.
/.../prog_tests/btf_dedup_split.c:368:6: warning: variable 'btf2' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (!ASSERT_OK(err, "btf_dedup"))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.../prog_tests/btf_dedup_split.c:424:12: note: uninitialized use occurs here
btf__free(btf2);
^~~~
/.../prog_tests/btf_dedup_split.c:368:2: note: remove the 'if' if its condition is always false
if (!ASSERT_OK(err, "btf_dedup"))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/.../prog_tests/btf_dedup_split.c:343:25: note: initialize the variable 'btf2' to silence this warning
struct btf *btf1, *btf2;
^
= NULLInitialize local variable btf2 = NULL and the warning is gone.
--- tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c +1 -1
@@ -340,7 +340,7 @@ static void btf_add_dup_struct_in_cu(struct btf *btf, int start_id)static void test_split_dup_struct_in_cu () { -struct btf *btf1, *btf2; +struct btf *btf1, *btf2 =NULL ;int err;/* generate the base data.. */
Signature · 1 line
2.30.2
Quoted 18 lines · Yonghong Song
The following warning is triggered when I used clang compiler to build the selftest.
/.../prog_tests/btf_dedup_split.c:368:6: warning: variable 'btf2' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (!ASSERT_OK(err, "btf_dedup")) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /.../prog_tests/btf_dedup_split.c:424:12: note: uninitialized use occurs here btf__free(btf2); ^~~~ /.../prog_tests/btf_dedup_split.c:368:2: note: remove the 'if' if its condition is always false if (!ASSERT_OK(err, "btf_dedup")) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /.../prog_tests/btf_dedup_split.c:343:25: note: initialize the variable 'btf2' to silence this warning struct btf *btf1, *btf2; ^ = NULL
Quoted 4 lines
Initialize local variable btf2 = NULL and the warning is gone.
Signed-off-by Yonghong Song <[email protected]>---
Added:
duplicated structs within CU")
and pushed to bpf-next. Thanks.
Quoted 19 lines
tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/btf_dedup_split.c +1
-2@@ -340,7 +340,7 @@ static void btf_add_dup_struct_in_cu(struct btf *btf, int start_id)static void test_split_dup_struct_in_cu () { -struct btf *btf1, *btf2; +struct btf *btf1, *btf2 =NULL ;int err;/* generate the base data.. */ --2.30.2
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:
Quoted 17 lines · On Wed, 8 Dec 2021 21:04:03 -0800 you wrote:
The following warning is triggered when I used clang compiler to build the selftest.
/.../prog_tests/btf_dedup_split.c:368:6: warning: variable 'btf2' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (!ASSERT_OK(err, "btf_dedup")) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /.../prog_tests/btf_dedup_split.c:424:12: note: uninitialized use occurs here btf__free(btf2); ^~~~ /.../prog_tests/btf_dedup_split.c:368:2: note: remove the 'if' if its condition is always false if (!ASSERT_OK(err, "btf_dedup")) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /.../prog_tests/btf_dedup_split.c:343:25: note: initialize the variable 'btf2' to silence this warning struct btf *btf1, *btf2; ^ = NULL
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next] selftests/bpf: fix a compilation warning
https://git.kernel.org/bpf/bpf-next/c/b540358e6c4d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html