]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests: kselftest_harness: fix Clang warning about zero-length format
authorJakub Kicinski <kuba@kernel.org>
Tue, 16 Apr 2024 15:10:48 +0000 (08:10 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 18 Apr 2024 01:35:49 +0000 (18:35 -0700)
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")
Tested-by: Sean Christopherson <seanjc@google.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Link: https://lore.kernel.org/r/20240416151048.1682352-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/kselftest.h
tools/testing/selftests/kselftest_harness.h

index 541bf192e30e6bcec377908643d41d1d1dbf765a..4eca3fd1292cf99be961eebc77fa4b57ec0c8721 100644 (file)
@@ -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)
index 4fd735e48ee7eea99702fcb3e27f539c887b15bc..adb15cae79abc7fe0fe013da6c56b28ca783ab85 100644 (file)
@@ -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)