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
This commit is contained in:
Richard Frith-MacDonald 2014-02-13 11:51:57 +00:00
parent 1316bf3a0f
commit 2bd91204be
2 changed files with 20 additions and 2 deletions

View file

@ -1,3 +1,9 @@
2014-02-13 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <lcampbel@akamai.com>
* Source/NSCalendarDate.m: Fixup millisecond formatting to match OSX

View file

@ -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;
}