diff options
Diffstat (limited to 'tests/test-vasprintf-posix.c')
-rw-r--r-- | tests/test-vasprintf-posix.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index 13b3a1bca9..46086ef251 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -3873,6 +3873,24 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) free (result); } + { /* Precision is ignored. */ + char *result; + int retval = + my_asprintf (&result, "%.0c %d", (unsigned char) 'x', 33, 44, 55); + ASSERT (strcmp (result, "x 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* NUL character. */ + char *result; + int retval = + my_asprintf (&result, "a%cz %d", '\0', 33, 44, 55); + ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0); + ASSERT (retval == 6); + free (result); + } + #if HAVE_WCHAR_T static wint_t L_x = (wchar_t) 'x'; @@ -3915,6 +3933,27 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) ASSERT (retval == strlen (result)); free (result); } + + { /* Precision is ignored. */ + char *result; + int retval = + my_asprintf (&result, "%.0lc %d", L_x, 33, 44, 55); + ASSERT (strcmp (result, "x 33") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { /* NUL character. */ + char *result; + int retval = + my_asprintf (&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); + free (result); + } #endif /* Test the support of the 'b' conversion specifier for binary output of |