From 017bda675b98b7a7fb96279ae08fe6f66c9f8af6 Mon Sep 17 00:00:00 2001 From: rfm Date: Thu, 13 Feb 2014 11:51:57 +0000 Subject: [PATCH] Fixup to use the heap if the required workspace buffer is too large. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37684 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 ++++++ Source/GSFormat.m | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fdde53529..1667f6097 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-02-13 Richard Frith-Macdonald + + * Source/GSFormat.m: Fix to cope with cases where a format specifies + a field width larger than can reasonably fit on the strack ... use + the heap. + 2014-02-13 Larry Campbell * Source/NSCalendarDate.m: Fixup millisecond formatting to match OSX diff --git a/Source/GSFormat.m b/Source/GSFormat.m index c8c000a8d..611d25cff 100644 --- a/Source/GSFormat.m +++ b/Source/GSFormat.m @@ -833,6 +833,7 @@ NSDictionary *locale) /* Buffer intermediate results. */ unichar work_buffer[1000]; unichar *workend; + int workend_malloced = 0; /* State for restartable multibyte character handling functions. */ @@ -1144,8 +1145,18 @@ NSDictionary *locale) if ((unsigned)(MAX (prec, width) + 32) > sizeof (work_buffer) / sizeof (unichar)) { - workend = ((unichar *) alloca ((MAX (prec, width) + 32) - * sizeof (unichar)) + (MAX (prec, width) + 32)); + size_t want = ((MAX (prec, width) + 32) + * sizeof (unichar)) + (MAX (prec, width) + 32); + + if (want > 168384) + { + workend = (unichar *)malloc(want); + workend_malloced = 1; + } + else + { + workend = (unichar *)alloca(want); + } } /* Process format specifiers. */ @@ -1933,6 +1944,7 @@ NSDictionary *locale) } all_done: + if (workend_malloced) free(workend); /* Unlock the stream. */ return; }