Skip to content

Commit f1a58f6

Browse files
committed
selftests/nolibc: avoid passing NULL to printf("%s")
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 <[email protected]> Acked-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Thomas Weißschuh <[email protected]>
1 parent ddae1d7 commit f1a58f6

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
@@ -542,7 +542,7 @@ int expect_strzr(const char *expr, int llen)
542542
{
543543
int ret = 0;
544544

545-
llen += printf(" = <%s> ", expr);
545+
llen += printf(" = <%s> ", expr ? expr : "(null)");
546546
if (expr) {
547547
ret = 1;
548548
result(llen, FAIL);
@@ -561,7 +561,7 @@ int expect_strnz(const char *expr, int llen)
561561
{
562562
int ret = 0;
563563

564-
llen += printf(" = <%s> ", expr);
564+
llen += printf(" = <%s> ", expr ? expr : "(null)");
565565
if (!expr) {
566566
ret = 1;
567567
result(llen, FAIL);

0 commit comments

Comments
 (0)