diff options
-rw-r--r-- | src/printf.c | 1 | ||||
-rw-r--r-- | src/vasprintf.c | 2 | ||||
-rw-r--r-- | tests/tprintf.c | 32 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/printf.c b/src/printf.c index 632a3f5c2..3a554e704 100644 --- a/src/printf.c +++ b/src/printf.c @@ -40,7 +40,6 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., # endif /* HAVE___VA_COPY */ #endif /* HAVE_VA_COPY */ -#include <errno.h> #include "mpfr-impl.h" #ifdef _MPFR_H_HAVE_FILE diff --git a/src/vasprintf.c b/src/vasprintf.c index 1aebd6950..4238923bf 100644 --- a/src/vasprintf.c +++ b/src/vasprintf.c @@ -52,6 +52,8 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include <stddef.h> /* for ptrdiff_t */ #endif +#include <errno.h> + #define MPFR_NEED_LONGLONG_H #include "mpfr-intmax.h" #include "mpfr-impl.h" diff --git a/tests/tprintf.c b/tests/tprintf.c index 25b70007f..b5f71a23d 100644 --- a/tests/tprintf.c +++ b/tests/tprintf.c @@ -26,6 +26,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #include <stdio.h> #include <stdlib.h> #include <stddef.h> +#include <errno.h> #include "mpfr-intmax.h" #include "mpfr-test.h" @@ -109,6 +110,33 @@ check_vprintf_failure (const char *fmt, ...) } static void +check_vprintf_overflow (const char *fmt, ...) +{ + va_list ap; + int r, e; + + va_start (ap, fmt); + errno = 0; + r = mpfr_vprintf (fmt, ap); + e = errno; + va_end (ap); + + if (r != -1 +#ifdef EOVERFLOW + || e != EOVERFLOW +#endif + ) + { + putchar ('\n'); + fprintf (stderr, "Error in mpfr_vprintf(\"%s\", ...)\n" + "Got r = %d, errno = %d\n", fmt, r, e); + exit (1); + } + + putchar ('\n'); +} + +static void check_invalid_format (void) { int i = 0; @@ -167,8 +195,8 @@ check_long_string (void) mpfr_set_ui (x, 1, MPFR_RNDN); mpfr_nextabove (x); - check_vprintf_failure ("%Rb", x); - check_vprintf_failure ("%RA %RA %Ra %Ra", x, x, x, x); + check_vprintf_overflow ("%Rb", x); + check_vprintf_overflow ("%RA %RA %Ra %Ra", x, x, x, x); mpfr_clear (x); } |