diff options
author | Bruno Haible <bruno@clisp.org> | 2023-04-01 11:45:23 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-04-01 11:45:23 +0200 |
commit | 154a389b7cc0654a4fbec0faf4f0ddc3e89a947a (patch) | |
tree | 1db12ccfbcc04e30c4643a41dfa6e3d4638e5969 /tests/test-vasprintf-posix.c | |
parent | 5386b7c76fc0ecf8b05003a5b6daaa33799d506f (diff) | |
download | gnulib-154a389b7cc0654a4fbec0faf4f0ddc3e89a947a.tar.gz |
vasnprintf-posix: Fix crash in narrow %lc directive (regr. 2023-03-21).
* lib/vasnprintf.c (VASNPRINTF): Negative results of local_wcrtomb can
now occur; handle them.
* tests/test-vasnprintf-posix.c (test_function): Test %lc directive with
a wint_t argument that is not a valid wide character.
* tests/test-snprintf-posix.h (test_function): Likewise.
* tests/test-sprintf-posix.h (test_function): Likewise.
* tests/test-vasnwprintf-posix.c (test_function): Likewise.
* tests/test-vasprintf-posix.c (test_function): Likewise.
Diffstat (limited to 'tests/test-vasprintf-posix.c')
-rw-r--r-- | tests/test-vasprintf-posix.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index 6a18413abb..e4cc0fb983 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -3954,6 +3954,26 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) ASSERT (retval == 5); free (result); } + + static wint_t L_invalid = (wchar_t) 0x76543210; + + { /* Invalid wide character. + The conversion may succeed or may fail, but it should not abort. */ + char *result; + int retval = + my_asprintf (&result, "%lc %d", L_invalid, 33, 44, 55); + if (retval >= 0) + free (result); + } + + { /* Invalid wide character and width. + The conversion may succeed or may fail, but it should not abort. */ + char *result; + int retval = + my_asprintf (&result, "%10lc %d", L_invalid, 33, 44, 55); + if (retval >= 0) + free (result); + } #endif /* Test the support of the 'x' conversion specifier for hexadecimal output of |