From c10ed91c3e4c96ca26fda15137f2d65655ecc742 Mon Sep 17 00:00:00 2001 From: BLooperZ Date: Tue, 31 Dec 2019 22:12:45 +0200 Subject: SCUMM: avoid allocating large buffers on stack --- engines/scumm/string.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'engines/scumm') diff --git a/engines/scumm/string.cpp b/engines/scumm/string.cpp index 633a67792c..c2a07fa54b 100644 --- a/engines/scumm/string.cpp +++ b/engines/scumm/string.cpp @@ -478,6 +478,13 @@ void ScummEngine::fakeBidiString(char *ltext, bool ignoreVerb) { int start = 0; char *text = ltext + ll; char *current = text; + + int bufferSize = 384; + char * const buff = (char *)calloc(sizeof(char), bufferSize); + assert(buff); + char * const stack = (char *)calloc(sizeof(char), bufferSize); + assert(stack); + while (1) { if (*current == 13 || *current == 0 || *current == -1 || *current == -2) { @@ -490,10 +497,8 @@ void ScummEngine::fakeBidiString(char *ltext, bool ignoreVerb) { continue; } - char buff[384]; - memset(buff, 0, sizeof(buff)); - char stack[384]; - memset(stack, 0, sizeof(stack)); + memset(buff, 0, bufferSize); + memset(stack, 0, bufferSize); int sthead = 0; char last = '\0'; @@ -546,6 +551,9 @@ void ScummEngine::fakeBidiString(char *ltext, bool ignoreVerb) { ltext[start + ipos + ll] = '\x80'; ltext[start + ipos + ll + 1] = '\0'; } + + free(buff); + free(stack); } void ScummEngine::CHARSET_1() { -- cgit v1.2.3