Mercurial > hg > octave-nkf > gnulib-hg
changeset 10394:4b3ac67aa7bc
vasnprintf-posix: handle large precision via %.*d
* lib/vasnprintf.c (VASNPRINTF): Don't pass precision to snprintf
when handling it ourselves.
* tests/test-vasnprintf-posix.c (test_function): Add test.
* tests/test-snprintf-posix.h (test_function): Likewise.
* tests/test-sprintf-posix.h (test_function): Likewise.
* tests/test-vasprintf-posix.c (test_function): Likewise.
Reported by Alain Guibert.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Mon, 01 Sep 2008 21:28:44 -0600 |
parents | 76ee0bae41ff |
children | 532b2255aeea |
files | ChangeLog lib/vasnprintf.c tests/test-snprintf-posix.h tests/test-sprintf-posix.h tests/test-vasnprintf-posix.c tests/test-vasprintf-posix.c |
diffstat | 6 files changed, 62 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-09-02 Eric Blake <ebb9@byu.net> + + vasnprintf-posix: handle large precision via %.*d + * lib/vasnprintf.c (VASNPRINTF): Don't pass precision to snprintf + when handling it ourselves. + * tests/test-vasnprintf-posix.c (test_function): Add test. + * tests/test-snprintf-posix.h (test_function): Likewise. + * tests/test-sprintf-posix.h (test_function): Likewise. + * tests/test-vasprintf-posix.c (test_function): Likewise. + Reported by Alain Guibert. + 2008-09-01 Eric Blake <ebb9@byu.net> c-stack: make configure-time check more robust
--- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4176,7 +4176,7 @@ abort (); prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; } - if (dp->precision_arg_index != ARG_NONE) + if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) { if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) abort ();
--- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -2950,6 +2950,18 @@ { char result[5000]; int retval = + my_snprintf (result, sizeof (result), "%.*d %d", 4000, 1234567, 99); + size_t i; + ASSERT (result != NULL); + for (i = 0; i < 4000 - 7; i++) + ASSERT (result[i] == '0'); + ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); + ASSERT (retval == strlen (result)); + } + + { + char result[5000]; + int retval = my_snprintf (result, sizeof (result), "%.4000d %d", -1234567, 99); size_t i; ASSERT (result != NULL);
--- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -2924,6 +2924,18 @@ { char result[5000]; int retval = + my_sprintf (result, "%.*d %d", 4000, 1234567, 99); + size_t i; + ASSERT (result != NULL); + for (i = 0; i < 4000 - 7; i++) + ASSERT (result[i] == '0'); + ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); + ASSERT (retval == strlen (result)); + } + + { + char result[5000]; + int retval = my_sprintf (result, "%.4000d %d", -1234567, 99); size_t i; ASSERT (result != NULL);
--- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -3457,6 +3457,19 @@ { size_t length; char *result = + my_asnprintf (NULL, &length, "%.*d %d", 4000, 1234567, 99); + size_t i; + ASSERT (result != NULL); + for (i = 0; i < 4000 - 7; i++) + ASSERT (result[i] == '0'); + ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); + ASSERT (length == strlen (result)); + free (result); + } + + { + size_t length; + char *result = my_asnprintf (NULL, &length, "%.4000d %d", -1234567, 99); size_t i; ASSERT (result != NULL);
--- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -3438,6 +3438,19 @@ { char *result; int retval = + my_asprintf (&result, "%.*d %d", 4000, 1234567, 99); + size_t i; + ASSERT (result != NULL); + for (i = 0; i < 4000 - 7; i++) + ASSERT (result[i] == '0'); + ASSERT (strcmp (result + 4000 - 7, "1234567 99") == 0); + ASSERT (retval == strlen (result)); + free (result); + } + + { + char *result; + int retval = my_asprintf (&result, "%.4000d %d", -1234567, 99); size_t i; ASSERT (result != NULL);