aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-12-19 08:29:56 +0000
committerUlrich Drepper <drepper@redhat.com>1999-12-19 08:29:56 +0000
commitb526f8ac5fa5e04ffe3aee151d777ad4c0747ece (patch)
treedb0e0f9f41101dc042b951098084cac41d76f3c5
parente9e9b245b98b8aeb8b8e898dce2b8c0f771602d6 (diff)
downloadglibc-b526f8ac5fa5e04ffe3aee151d777ad4c0747ece.zip
glibc-b526f8ac5fa5e04ffe3aee151d777ad4c0747ece.tar.gz
glibc-b526f8ac5fa5e04ffe3aee151d777ad4c0747ece.tar.bz2
Update.
1999-12-19 Ulrich Drepper <drepper@cygnus.com> * stdio-common/printf_fp.c (__printf_fp): Allocate buffer to generate mantissa output in using malloc if it is larger than 20000 characters. Reported by Jim Meyering <meyering@ascend.com>.
-rw-r--r--ChangeLog7
-rw-r--r--stdio-common/printf_fp.c19
2 files changed, 24 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 32beebe..b636cdd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+1999-12-19 Ulrich Drepper <drepper@cygnus.com>
+
+ * stdio-common/printf_fp.c (__printf_fp): Allocate buffer to
+ generate mantissa output in using malloc if it is larger than
+ 20000 characters.
+ Reported by Jim Meyering <meyering@ascend.com>.
+
1999-12-18 Ulrich Drepper <drepper@cygnus.com>
* misc/sys/cdefs.h: Define __attribute_malloc__ according to
diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c
index 0a2efb7..13598e3 100644
--- a/stdio-common/printf_fp.c
+++ b/stdio-common/printf_fp.c
@@ -747,6 +747,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;
@@ -816,8 +817,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 = (char *) alloca (2 + chars_needed);
cp = startp = buffer + 2; /* Let room for rounding. */
/* Do the real work: put digits in allocated buffer. */
@@ -1025,6 +1036,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;
}