summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-05-28 21:58:53 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2017-05-28 21:58:53 +0000
commit79da739d645112dc7b9862061c38172dc31049a8 (patch)
treede1ef0f2d0cdc0cb5d9ef97e6ea0d772b2e41a10
parent27686683b4dc9bc7469b0b74c29958f1b8c6135d (diff)
downloadmpfr-79da739d645112dc7b9862061c38172dc31049a8.tar.gz
[src] Moved "#include <errno.h>" from printf.c to vasprintf.c (this
should have been done in r5230, where EOVERFLOW was moved). (merged changeset r11532 from the trunk) [tests/tprintf.c] Added errno test for check_long_string(), which is called when MPFR_CHECK_LARGEMEM is defined, to trigger the above bug. A merge from the trunk was not possible due to many changes in the mpfr_*printf code and the tests. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@11539 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/printf.c1
-rw-r--r--src/vasprintf.c2
-rw-r--r--tests/tprintf.c32
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);
}