Commit 9b7bd5ad authored by Dino Bollinger's avatar Dino Bollinger
Browse files

Duke3D: Prevent double allocation of qputs strings inside a switch.

Fixes #102
parent 2b4fa55f
......@@ -68,6 +68,7 @@ static bool g_dynamicTileMapping;
static bool g_labelsOnly;
static bool g_processingState;
static bool g_skipBranch;
static bool g_switchCountPhase = false;
static int g_checkingIfElse;
static int g_checkingSwitch;
......@@ -1940,15 +1941,19 @@ static bool C_CheckEmptyBranch(int tw, intptr_t lastScriptPtr)
static int C_CountCaseStatements()
{
char *const temptextptr = textptr;
int const backupLineNumber = g_lineNumber;
int const backupNumCases = g_numCases;
intptr_t const casePtrOffset = g_caseTablePtr - apScript;
intptr_t const scriptPtrOffset = g_scriptPtr - apScript;
char *const temptextptr = textptr;
int const backupLineNumber = g_lineNumber;
int const backupNumCases = g_numCases;
intptr_t const casePtrOffset = g_caseTablePtr - apScript;
intptr_t const scriptPtrOffset = g_scriptPtr - apScript;
bool const backupSwitchCount = g_switchCountPhase;
g_numCases = 0;
g_caseTablePtr = NULL;
g_switchCountPhase = true;
C_ParseCommand(true);
g_switchCountPhase = backupSwitchCount;
// since we processed the endswitch, we need to re-increment g_checkingSwitch
g_checkingSwitch++;
......@@ -5631,6 +5636,7 @@ repeatcase:
case CON_DEFINEQUOTE:
case CON_REDEFINEQUOTE:
if (tw == CON_DEFINEQUOTE)
{
g_scriptPtr--;
......@@ -5659,7 +5665,7 @@ repeatcase:
scriptSkipSpaces();
if (tw == CON_REDEFINEQUOTE)
if (tw == CON_REDEFINEQUOTE && !g_switchCountPhase)
{
if (apXStrings[g_numXStrings] == NULL)
apXStrings[g_numXStrings] = (char *)Xcalloc(MAXQUOTELEN,sizeof(uint8_t));
......@@ -5676,10 +5682,14 @@ repeatcase:
break;
}
*/
if (tw == CON_DEFINEQUOTE)
*(apStrings[k]+i) = *textptr;
else
*(apXStrings[g_numXStrings]+i) = *textptr;
if (!g_switchCountPhase)
{
if (tw == CON_DEFINEQUOTE)
*(apStrings[k]+i) = *textptr;
else
*(apXStrings[g_numXStrings]+i) = *textptr;
}
textptr++,i++;
if (EDUKE32_PREDICT_FALSE(i >= MAXQUOTELEN))
{
......@@ -5691,15 +5701,18 @@ repeatcase:
}
}
if (tw == CON_DEFINEQUOTE)
if (!g_switchCountPhase)
{
if ((unsigned)k < MAXQUOTES)
*(apStrings[k]+i) = '\0';
}
else
{
*(apXStrings[g_numXStrings]+i) = '\0';
scriptWriteValue(g_numXStrings++);
if (tw == CON_DEFINEQUOTE)
{
if ((unsigned)k < MAXQUOTES)
*(apStrings[k]+i) = '\0';
}
else
{
*(apXStrings[g_numXStrings]+i) = '\0';
scriptWriteValue(g_numXStrings++);
}
}
continue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment