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