diff options
Diffstat (limited to 'tests/test-sprintf-posix.h')
-rw-r--r-- | tests/test-sprintf-posix.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index 863d084b99..d745a1109b 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -3006,6 +3006,20 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) ASSERT (retval == strlen (result)); } + { /* Precision is ignored. */ + int retval = + my_sprintf (result, "%.0c %d", (unsigned char) 'x', 33, 44, 55); + ASSERT (strcmp (result, "x 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NUL character. */ + int retval = + my_sprintf (result, "a%cz %d", '\0', 33, 44, 55); + ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0); + ASSERT (retval == 6); + } + #if HAVE_WCHAR_T static wint_t L_x = (wchar_t) 'x'; @@ -3036,6 +3050,23 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) ASSERT (strcmp (result, "x 33") == 0); ASSERT (retval == strlen (result)); } + + { /* Precision is ignored. */ + int retval = + my_sprintf (result, "%.0lc %d", L_x, 33, 44, 55); + ASSERT (strcmp (result, "x 33") == 0); + ASSERT (retval == strlen (result)); + } + + { /* NUL character. */ + int retval = + my_sprintf (result, "a%lcz %d", (wint_t) L'\0', 33, 44, 55); + /* No NUL byte between 'a' and 'z'. This is surprising, but is a + consequence of how POSIX:2018 and ISO C 23 specify the handling + of %lc. */ + ASSERT (memcmp (result, "az 33\0", 5 + 1) == 0); + ASSERT (retval == 5); + } #endif /* Test the support of the 'b' conversion specifier for binary output of |