* [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format
@ 2024-04-16 15:10 Jakub Kicinski
2024-04-16 15:23 ` Sean Christopherson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2024-04-16 15:10 UTC (permalink / raw)
To: davem
Cc: netdev, edumazet, pabeni, Jakub Kicinski, Sean Christopherson,
shuah, keescook, usama.anjum, linux-kselftest, llvm
Apparently it's more legal to pass the format as NULL, than
it is to use an empty string. Clang complains about empty
formats:
./../kselftest_harness.h:1207:30: warning: format string is empty
[-Wformat-zero-length]
1207 | diagnostic ? "%s" : "", diagnostic);
| ^~
1 warning generated.
Reported-by: Sean Christopherson <seanjc@google.com>
Link: https://lore.kernel.org/all/20240409224256.1581292-1-seanjc@google.com
Fixes: 378193eff339 ("selftests: kselftest_harness: let PASS / FAIL provide diagnostic")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
---
CC: shuah@kernel.org
CC: keescook@chromium.org
CC: usama.anjum@collabora.com
CC: linux-kselftest@vger.kernel.org
CC: llvm@lists.linux.dev
---
tools/testing/selftests/kselftest.h | 10 ++++++----
tools/testing/selftests/kselftest_harness.h | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
index 541bf192e30e..4eca3fd1292c 100644
--- a/tools/testing/selftests/kselftest.h
+++ b/tools/testing/selftests/kselftest.h
@@ -288,15 +288,17 @@ void ksft_test_result_code(int exit_code, const char *test_name,
}
/* Docs seem to call for double space if directive is absent */
- if (!directive[0] && msg[0])
+ if (!directive[0] && msg)
directive = " # ";
- va_start(args, msg);
printf("%s %u %s%s", tap_code, ksft_test_num(), test_name, directive);
errno = saved_errno;
- vprintf(msg, args);
+ if (msg) {
+ va_start(args, msg);
+ vprintf(msg, args);
+ va_end(args);
+ }
printf("\n");
- va_end(args);
}
static inline int ksft_exit_pass(void)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 4fd735e48ee7..adb15cae79ab 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -1202,7 +1202,7 @@ void __run_test(struct __fixture_metadata *f,
diagnostic = "unknown";
ksft_test_result_code(t->exit_code, test_name,
- diagnostic ? "%s" : "", diagnostic);
+ diagnostic ? "%s" : NULL, diagnostic);
}
static int test_harness_run(int argc, char **argv)
--
2.44.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format
2024-04-16 15:10 [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format Jakub Kicinski
@ 2024-04-16 15:23 ` Sean Christopherson
2024-04-16 15:24 ` Muhammad Usama Anjum
2024-04-18 2:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2024-04-16 15:23 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, shuah, keescook, usama.anjum,
linux-kselftest, llvm
On Tue, Apr 16, 2024, Jakub Kicinski wrote:
> Apparently it's more legal to pass the format as NULL, than
> it is to use an empty string. Clang complains about empty
> formats:
>
> ./../kselftest_harness.h:1207:30: warning: format string is empty
> [-Wformat-zero-length]
> 1207 | diagnostic ? "%s" : "", diagnostic);
> | ^~
> 1 warning generated.
>
> Reported-by: Sean Christopherson <seanjc@google.com>
> Link: https://lore.kernel.org/all/20240409224256.1581292-1-seanjc@google.com
> Fixes: 378193eff339 ("selftests: kselftest_harness: let PASS / FAIL provide diagnostic")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Thanks Jakub!
Tested-by: Sean Christopherson <seanjc@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format
2024-04-16 15:10 [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format Jakub Kicinski
2024-04-16 15:23 ` Sean Christopherson
@ 2024-04-16 15:24 ` Muhammad Usama Anjum
2024-04-18 2:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Muhammad Usama Anjum @ 2024-04-16 15:24 UTC (permalink / raw)
To: Jakub Kicinski, davem
Cc: Muhammad Usama Anjum, netdev, edumazet, pabeni,
Sean Christopherson, shuah, keescook, linux-kselftest, llvm
On 4/16/24 8:10 PM, Jakub Kicinski wrote:
> Apparently it's more legal to pass the format as NULL, than
> it is to use an empty string. Clang complains about empty
> formats:
>
> ./../kselftest_harness.h:1207:30: warning: format string is empty
> [-Wformat-zero-length]
> 1207 | diagnostic ? "%s" : "", diagnostic);
> | ^~
> 1 warning generated.
>
> Reported-by: Sean Christopherson <seanjc@google.com>
> Link: https://lore.kernel.org/all/20240409224256.1581292-1-seanjc@google.com
> Fixes: 378193eff339 ("selftests: kselftest_harness: let PASS / FAIL provide diagnostic")
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> ---
> CC: shuah@kernel.org
> CC: keescook@chromium.org
> CC: usama.anjum@collabora.com
> CC: linux-kselftest@vger.kernel.org
> CC: llvm@lists.linux.dev
> ---
> tools/testing/selftests/kselftest.h | 10 ++++++----
> tools/testing/selftests/kselftest_harness.h | 2 +-
> 2 files changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h
> index 541bf192e30e..4eca3fd1292c 100644
> --- a/tools/testing/selftests/kselftest.h
> +++ b/tools/testing/selftests/kselftest.h
> @@ -288,15 +288,17 @@ void ksft_test_result_code(int exit_code, const char *test_name,
> }
>
> /* Docs seem to call for double space if directive is absent */
> - if (!directive[0] && msg[0])
> + if (!directive[0] && msg)
> directive = " # ";
>
> - va_start(args, msg);
> printf("%s %u %s%s", tap_code, ksft_test_num(), test_name, directive);
> errno = saved_errno;
> - vprintf(msg, args);
> + if (msg) {
> + va_start(args, msg);
> + vprintf(msg, args);
> + va_end(args);
> + }
> printf("\n");
> - va_end(args);
> }
>
> static inline int ksft_exit_pass(void)
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index 4fd735e48ee7..adb15cae79ab 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -1202,7 +1202,7 @@ void __run_test(struct __fixture_metadata *f,
> diagnostic = "unknown";
>
> ksft_test_result_code(t->exit_code, test_name,
> - diagnostic ? "%s" : "", diagnostic);
> + diagnostic ? "%s" : NULL, diagnostic);
> }
>
> static int test_harness_run(int argc, char **argv)
--
BR,
Muhammad Usama Anjum
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format
2024-04-16 15:10 [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format Jakub Kicinski
2024-04-16 15:23 ` Sean Christopherson
2024-04-16 15:24 ` Muhammad Usama Anjum
@ 2024-04-18 2:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-18 2:10 UTC (permalink / raw)
To: Jakub Kicinski
Cc: davem, netdev, edumazet, pabeni, seanjc, shuah, keescook,
usama.anjum, linux-kselftest, llvm
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 16 Apr 2024 08:10:48 -0700 you wrote:
> Apparently it's more legal to pass the format as NULL, than
> it is to use an empty string. Clang complains about empty
> formats:
>
> ./../kselftest_harness.h:1207:30: warning: format string is empty
> [-Wformat-zero-length]
> 1207 | diagnostic ? "%s" : "", diagnostic);
> | ^~
> 1 warning generated.
>
> [...]
Here is the summary with links:
- [net] selftests: kselftest_harness: fix Clang warning about zero-length format
https://git.kernel.org/netdev/net/c/caed8eba2215
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-18 2:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-16 15:10 [PATCH net] selftests: kselftest_harness: fix Clang warning about zero-length format Jakub Kicinski
2024-04-16 15:23 ` Sean Christopherson
2024-04-16 15:24 ` Muhammad Usama Anjum
2024-04-18 2:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox