selftests: kselftest_harness: fix Clang warning about zero-length format
Subsystems (4)
Jakub Kicinski
maintainerPATCH 1/1 selftests: kselftest_harness: fix Clang warning about zero-length format
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.
---
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- tools/testing/selftests/kselftest.h | 10 ++++++---- tools/testing/selftests/kselftest_harness.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-)
tools/testing/selftests/kselftest.h +6 -4
@@ -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 )
tools/testing/selftests/kselftest_harness.h +1 -1
@@ -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)
Signature · 1 line
2.44.0
Quoted 10 lines · Jakub Kicinski
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.
Quoted 4 lines
Reported-by Sean Christopherson <[email protected]>Fixes 378193eff339 ("selftests: kselftest_harness: let PASS / FAIL provide diagnostic")Signed-off-by Jakub Kicinski <[email protected]>
Thanks Jakub!
Quoted 10 lines · Jakub Kicinski
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.
Quoted 4 lines
Reported-by Sean Christopherson <[email protected]>Fixes 378193eff339 ("selftests: kselftest_harness: let PASS / FAIL provide diagnostic")Signed-off-by Jakub Kicinski <[email protected]>
Quoted 51 lines
---
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]--- tools/testing/selftests/kselftest.h | 10 ++++++---- tools/testing/selftests/kselftest_harness.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-)tools/testing/selftests/kselftest.h +6
-4@@ -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 )tools/testing/selftests/kselftest_harness.h +1
-1@@ -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)
Signature · 2 lines
BR, Muhammad Usama Anjum
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html