summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/efgcvt_r.c3
-rw-r--r--misc/tst-efgcvt.c19
2 files changed, 19 insertions, 3 deletions
diff --git a/misc/efgcvt_r.c b/misc/efgcvt_r.c
index 80770e6a82..1a039efc0b 100644
--- a/misc/efgcvt_r.c
+++ b/misc/efgcvt_r.c
@@ -101,7 +101,8 @@ APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len)
 
   n = __snprintf (buf, len, "%.*" FLOAT_FMT_FLAG "f", MIN (ndigit, NDIGIT_MAX),
 		  value);
-  if (n < 0)
+  /* Check for a too small buffer.  */
+  if (n >= len)
     return -1;
 
   i = 0;
diff --git a/misc/tst-efgcvt.c b/misc/tst-efgcvt.c
index cfbaa21cb1..74dd6bd8d3 100644
--- a/misc/tst-efgcvt.c
+++ b/misc/tst-efgcvt.c
@@ -120,9 +120,10 @@ test (testcase tests[], efcvt_func efcvt, const char *name)
 void
 special (void)
 {
-  int decpt, sign;
+  int decpt, sign, res;
   char *p;
-
+  char buf [1024];
+  
   p = ecvt (NAN, 10, &decpt, &sign);
   if (sign != 0 || strcmp (p, "nan") != 0)
     output_error ("ecvt", NAN, 10, "nan", 0, 0, p, decpt, sign);
@@ -135,6 +136,20 @@ special (void)
   (void) ecvt (123.456, 10000, &decpt, &sign);
   (void) fcvt (123.456, 10000, &decpt, &sign);
 
+  /* Some tests for for the reentrant functions.  */
+  /* Use a too small buffer.  */
+  res = ecvt_r (123.456, 10, &decpt, &sign, buf, 1);
+  if (res == 0)
+    {
+      printf ("ecvt_r with a too small buffer was succesful.\n");
+      ++error_count;
+    }
+  res = fcvt_r (123.456, 10, &decpt, &sign, buf, 1);
+  if (res == 0)
+    {
+      printf ("fcvt_r with a too small buffer was succesful.\n");
+      ++error_count;
+    }
 }