Skip to content

Commit caed8eb

Browse files
committed
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. Reported-by: Sean Christopherson <[email protected]> Link: https://lore.kernel.org/all/[email protected] Fixes: 378193e ("selftests: kselftest_harness: let PASS / FAIL provide diagnostic") Tested-by: Sean Christopherson <[email protected]> Reviewed-by: Muhammad Usama Anjum <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0f022d3 commit caed8eb

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

tools/testing/selftests/kselftest.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,17 @@ void ksft_test_result_code(int exit_code, const char *test_name,
288288
}
289289

290290
/* Docs seem to call for double space if directive is absent */
291-
if (!directive[0] && msg[0])
291+
if (!directive[0] && msg)
292292
directive = " # ";
293293

294-
va_start(args, msg);
295294
printf("%s %u %s%s", tap_code, ksft_test_num(), test_name, directive);
296295
errno = saved_errno;
297-
vprintf(msg, args);
296+
if (msg) {
297+
va_start(args, msg);
298+
vprintf(msg, args);
299+
va_end(args);
300+
}
298301
printf("\n");
299-
va_end(args);
300302
}
301303

302304
static inline int ksft_exit_pass(void)

tools/testing/selftests/kselftest_harness.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ void __run_test(struct __fixture_metadata *f,
12021202
diagnostic = "unknown";
12031203

12041204
ksft_test_result_code(t->exit_code, test_name,
1205-
diagnostic ? "%s" : "", diagnostic);
1205+
diagnostic ? "%s" : NULL, diagnostic);
12061206
}
12071207

12081208
static int test_harness_run(int argc, char **argv)

0 commit comments

Comments
 (0)