]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(__printf_fp): Allocate buffer to generate mantissa output in using
authorUlrich Drepper <drepper@redhat.com>
Sun, 19 Dec 1999 08:26:20 +0000 (08:26 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sun, 19 Dec 1999 08:26:20 +0000 (08:26 +0000)
malloc if it is larger than 20000 characters.

stdio-common/printf_fp.c

index c75289a3a94d80427e0494ebe4f04e3133fa2c28..4ecf6bf3b3fb1137bad9ab7100a44d6093e712f8 100644 (file)
@@ -724,6 +724,7 @@ __printf_fp (FILE *fp,
   {
     int width = info->width;
     char *buffer, *startp, *cp;
+    int buffer_malloced;
     int chars_needed;
     int expscale;
     int intdig_max, intdig_no = 0;
@@ -790,8 +791,18 @@ __printf_fp (FILE *fp,
 
     /* Allocate buffer for output.  We need two more because while rounding
        it is possible that we need two more characters in front of all the
-       other output.  */
-    buffer = alloca (2 + chars_needed);
+       other output.  If the amount of memory we have to allocate is too
+       large use `malloc' instead of `alloca'.  */
+    buffer_malloced = chars_needed > 20000;
+    if (buffer_malloced)
+      {
+       buffer = (char *) malloc (2 + chars_needed);
+       if (buffer == NULL)
+         /* Signal an error to the caller.  */
+         return -1;
+      }
+    else
+      buffer = alloca (2 + chars_needed);
     cp = startp = buffer + 2;  /* Let room for rounding.  */
 
     /* Do the real work: put digits in allocated buffer.  */
@@ -999,6 +1010,10 @@ __printf_fp (FILE *fp,
 
     if (info->left && width > 0)
       PADN (info->pad, width);
+
+    /* Free the memory if necessary.  */
+    if (buffer_malloced)
+      free (buffer);
   }
   return done;
 }