tests/sprintf: Remove tests with NULL FILE pointer

The C language says that use of a NULL FILE pointer with stdio functions is
undefined behavior. Let's just remove them instead of expecting the minimal
C library to exhibit a specific behavior in this case.

This also avoids problems when not using -ffreestanding as in that case,
the C compiler may generate warnings, or even cause undefined behavior on
its own.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard
2023-04-20 13:06:58 -07:00
committed by Christopher Friedt
parent 25b2db74e0
commit 1a830e2af6
-23
View File
@@ -791,10 +791,6 @@ ZTEST(sprintf, test_fprintf)
ret = fprintf(stdout, "");
zassert_equal(ret, 0, "fprintf failed!");
#if !defined(CONFIG_PICOLIBC) && !defined(CONFIG_ARMCLANG_STD_LIBC) /* this is UB */
ret = fprintf(NULL, "%d", i);
zassert_equal(ret, EOF, "fprintf failed!");
#endif
}
@@ -823,10 +819,6 @@ ZTEST(sprintf, test_vfprintf)
ret = WriteFrmtd_vf(stdout, "11\n");
zassert_equal(ret, 3, "vfprintf \"11\" failed");
#ifndef CONFIG_PICOLIBC /* this is UB */
ret = WriteFrmtd_vf(NULL, "This %d", 3);
zassert_equal(ret, EOF, "vfprintf \"This 3\" failed");
#endif
}
/**
@@ -883,30 +875,15 @@ ZTEST(sprintf, test_put)
ret = fputs("This 3\n", stderr);
zassert_equal(ret, 0, "fputs \"This 3\" failed");
#if !defined(CONFIG_PICOLIBC) && !defined(CONFIG_ARMCLANG_STD_LIBC) /* this is UB */
ret = fputs("This 3", NULL);
zassert_equal(ret, EOF, "fputs \"This 3\" failed");
#endif
ret = puts("This 3");
zassert_equal(ret, 0, "puts \"This 3\" failed");
ret = fputc('T', stdout);
zassert_equal(ret, 84, "fputc \'T\' failed");
#if !defined(CONFIG_PICOLIBC) && !defined(CONFIG_ARMCLANG_STD_LIBC) /* this is UB */
ret = fputc('T', NULL);
zassert_equal(ret, EOF, "fputc \'T\' failed");
#endif
ret = putc('T', stdout);
zassert_equal(ret, 84, "putc \'T\' failed");
#if !defined(CONFIG_PICOLIBC) && !defined(CONFIG_ARMCLANG_STD_LIBC) /* this is UB */
ret = putc('T', NULL);
zassert_equal(ret, EOF, "putc \'T\' failed");
#endif
ret = fputc('T', stderr);
zassert_equal(ret, 84, "fputc \'T\' failed");