]> git.baikalelectronics.ru Git - kernel.git/commit
selftests/bpf: Fix a compiler warning in local_storage test
authorKP Singh <kpsingh@kernel.org>
Tue, 2 Feb 2021 21:37:30 +0000 (21:37 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 3 Feb 2021 05:21:55 +0000 (21:21 -0800)
commit73905e0b56d10982a5c5f0ea9fe45e647eed5f12
tree4795fef5727db1faa50629a7c602823091021d6f
parentf33f93ce3900473dafb49bf5c2ae4da598973866
selftests/bpf: Fix a compiler warning in local_storage test

Some compilers trigger a warning when tmp_dir_path is allocated
with a fixed size of 64-bytes and used in the following snprintf:

  snprintf(tmp_exec_path, sizeof(tmp_exec_path), "%s/copy_of_rm",
   tmp_dir_path);

  warning: ‘/copy_of_rm’ directive output may be truncated writing 11
  bytes into a region of size between 1 and 64 [-Wformat-truncation=]

This is because it assumes that tmp_dir_path can be a maximum of 64
bytes long and, therefore, the end-result can get truncated. Fix it by
not using a fixed size in the initialization of tmp_dir_path which
allows the compiler to track actual size of the array better.

Fixes: 95889d55cf52 ("bpf: Update local storage test to check handling of null ptrs")
Signed-off-by: KP Singh <kpsingh@kernel.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210202213730.1906931-1-kpsingh@kernel.org
tools/testing/selftests/bpf/prog_tests/test_local_storage.c