diff mbox series

[net] selftests: kselftest_harness: fix Clang warning about zero-length format

Message ID 20240416151048.1682352-1-kuba@kernel.org (mailing list archive)
State Accepted
Commit caed8eba221533123192d39cc947f45cbb1e1db5
Delegated to: Netdev Maintainers
Headers show
Series [net] selftests: kselftest_harness: fix Clang warning about zero-length format | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 6 maintainers not CCed: nathan@kernel.org justinstitt@google.com luto@amacapital.net ndesaulniers@google.com wad@chromium.org morbo@google.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 29 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 53 this patch: 53
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-18--00-00 (tests: 961)

Commit Message

Jakub Kicinski April 16, 2024, 3:10 p.m. UTC
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(-)

Comments

Sean Christopherson April 16, 2024, 3:23 p.m. UTC | #1
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>
Muhammad Usama Anjum April 16, 2024, 3:24 p.m. UTC | #2
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)
patchwork-bot+netdevbpf@kernel.org April 18, 2024, 2:10 a.m. UTC | #3
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!
diff mbox series

Patch

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)