Commit 6256d4bf authored by Dino Bollinger's avatar Dino Bollinger

Duke3D: Fix internal compiler errors when script buffer is resized.

parent e3109037
......@@ -1046,7 +1046,7 @@ static void C_SetScriptSize(int32_t newsize)
{
if (BITPTR_IS_POINTER(i))
{
if (EDUKE32_PREDICT_FALSE(apScript[i] < (intptr_t)apScript || apScript[i] >= (intptr_t)g_scriptPtr))
if (EDUKE32_PREDICT_FALSE(apScript[i] < (intptr_t)apScript || apScript[i] > (intptr_t)g_scriptPtr))
{
g_errorCnt++;
buildprint("Internal compiler error at ", i, " (0x", hex(i), ")\n");
......@@ -1060,11 +1060,17 @@ static void C_SetScriptSize(int32_t newsize)
G_Util_PtrToIdx2(&g_tile[0].execPtr, MAXTILES, sizeof(tiledata_t), apScript, P2I_FWD_NON0);
G_Util_PtrToIdx2(&g_tile[0].loadPtr, MAXTILES, sizeof(tiledata_t), apScript, P2I_FWD_NON0);
size_t old_bitptr_size = (((g_scriptSize + 7) >> 3) + 1) * sizeof(uint8_t);
size_t new_bitptr_size = (((newsize + 7) >> 3) + 1) * sizeof(uint8_t);
auto newscript = (intptr_t *)Xrealloc(apScript, newsize * sizeof(intptr_t));
bitptr = (uint8_t *)Xrealloc(bitptr, (((newsize + 7) >> 3) + 1) * sizeof(uint8_t));
bitptr = (uint8_t *)Xrealloc(bitptr, new_bitptr_size);
if (newsize > g_scriptSize)
{
Bmemset(&newscript[g_scriptSize], 0, (newsize - g_scriptSize) * sizeof(intptr_t));
Bmemset(&bitptr[old_bitptr_size], 0, new_bitptr_size - old_bitptr_size);
}
if (apScript != newscript)
{
......
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