]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
fcvt_r): Handle illegal NDIGIT correctly.
authorUlrich Drepper <drepper@redhat.com>
Sun, 1 Feb 1998 15:17:18 +0000 (15:17 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sun, 1 Feb 1998 15:17:18 +0000 (15:17 +0000)
misc/efgcvt_r.c

index 7ad057fcb727f91ab2151e0fc6048ef4d654cfff..01889a27c50a73224b319bd7e02a70120aedfda7 100644 (file)
@@ -1,5 +1,5 @@
 /* Compatibility functions for floating point formatting, reentrant versions.
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -66,6 +66,17 @@ APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len)
       if (*sign)
        value = -value;
     }
+  else
+    /* Value is Inf or NaN.  */
+    *sign = 0;
+
+  if (ndigit <= 0)
+    {
+      if (len > 0)
+       buf[0] = '\0';
+      *decpt = 0;
+      return 0;
+    }
 
   n = snprintf (buf, len, "%.*" FLOAT_FMT_FLAG "f", ndigit, value);
   if (n < 0)
@@ -77,11 +88,8 @@ APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len)
   *decpt = i;
 
   if (i == 0)
-    {
-      /* Value is Inf or NaN.  */
-      *sign = 0;
-      return 0;
-    }
+    /* Value is Inf or NaN.  */
+    return 0;
 
   if (i < n)
     {
@@ -89,7 +97,7 @@ APPEND (FUNC_PREFIX, fcvt_r) (value, ndigit, decpt, sign, buf, len)
        ++i;
       while (i < n && !isdigit (buf[i]));
       memmove (&buf[*decpt], &buf[i], n - i);
-      buf[n - (i - *decpt)] = 0;
+      buf[n - (i - *decpt)] = '\0';
     }
 
   return 0;