Skip to content

Commit e9df4c6

Browse files
t-8chgregkh
authored andcommitted
selftests/nolibc: avoid passing NULL to printf("%s")
[ Upstream commit f1a58f6 ] Clang on higher optimization levels detects that NULL is passed to printf("%s") and warns about it. While printf() from nolibc gracefully handles that NULL, it is undefined behavior as per POSIX, so the warning is reasonable. Avoid the warning by transforming NULL into a non-NULL placeholder. Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://lore.kernel.org/r/20240807-nolibc-llvm-v2-8-c20f2f5fc7c2@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent fc975b8 commit e9df4c6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ int expect_strzr(const char *expr, int llen)
522522
{
523523
int ret = 0;
524524

525-
llen += printf(" = <%s> ", expr);
525+
llen += printf(" = <%s> ", expr ? expr : "(null)");
526526
if (expr) {
527527
ret = 1;
528528
result(llen, FAIL);
@@ -541,7 +541,7 @@ int expect_strnz(const char *expr, int llen)
541541
{
542542
int ret = 0;
543543

544-
llen += printf(" = <%s> ", expr);
544+
llen += printf(" = <%s> ", expr ? expr : "(null)");
545545
if (!expr) {
546546
ret = 1;
547547
result(llen, FAIL);

0 commit comments

Comments
 (0)