Add VM_ASSERT() macro for handling VM error conditions

This is for errors that simply check a condition (surrounded with EDUKE32_PREDICT_FALSE) and bail out with CON_ERRPRINTF() and abort_after_error(). Not everything that fits this description has been transitioned to use the new macro yet.

git-svn-id: https://svn.eduke32.com/eduke32@7638 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-05-19 03:53:34 +00:00 committed by Christoph Oelckers
parent f8fba45117
commit d1af530b01

View file

@ -1289,6 +1289,16 @@ void Screen_Play(void)
# define abort_after_error(...) continue // non-threaded dispatch handles this in the loop condition in VM_Execute() # define abort_after_error(...) continue // non-threaded dispatch handles this in the loop condition in VM_Execute()
#endif #endif
#define VM_ASSERT(condition, ...) \
do \
{ \
if (EDUKE32_PREDICT_FALSE(!(condition))) \
{ \
CON_ERRPRINTF(__VA_ARGS__); \
abort_after_error(); \
} \
} while (0)
GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/) GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
{ {
native_t loopcnt = loop; native_t loopcnt = loop;
@ -1994,11 +2004,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const nValue = Gv_GetVarX(*insptr++); int const nValue = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE(!nValue)) VM_ASSERT(nValue, "divide by zero!\n");
{
CON_CRITICALERRPRINTF("divide by zero!\n");
abort_after_error();
}
Gv_DivVar(tw, nValue); Gv_DivVar(tw, nValue);
dispatch(); dispatch();
@ -2261,11 +2267,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const nValue = Gv_GetVarX(*insptr++); int const nValue = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE(!nValue)) VM_ASSERT(nValue, "mod by zero!\n");
{
CON_CRITICALERRPRINTF("mod by zero!\n");
abort_after_error();
}
Gv_ModVar(tw, nValue); Gv_ModVar(tw, nValue);
dispatch(); dispatch();
@ -2370,11 +2372,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const lVar1 = *insptr++; int const lVar1 = *insptr++;
int const lVar2 = *insptr++; int const lVar2 = *insptr++;
if (EDUKE32_PREDICT_FALSE((unsigned)lSprite >= MAXSPRITES)) VM_ASSERT((unsigned)lSprite < MAXSPRITES, "invalid sprite %d\n", lSprite);
{
CON_ERRPRINTF("invalid sprite %d\n", lSprite);
abort_after_error();
}
if (tw == CON_SETACTORVAR) if (tw == CON_SETACTORVAR)
Gv_SetVar(lVar1, Gv_GetVarX(lVar2), lSprite, vm.playerNum); Gv_SetVar(lVar1, Gv_GetVarX(lVar2), lSprite, vm.playerNum);
@ -2392,11 +2390,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const lVar1 = *insptr++; int const lVar1 = *insptr++;
int const lVar2 = *insptr++; int const lVar2 = *insptr++;
if (EDUKE32_PREDICT_FALSE((unsigned)playerNum >= (unsigned)g_mostConcurrentPlayers)) VM_ASSERT((unsigned)playerNum < (unsigned)g_mostConcurrentPlayers, "invalid player %d\n", playerNum);
{
CON_ERRPRINTF("invalid player %d\n", playerNum);
abort_after_error();
}
if (tw == CON_SETPLAYERVAR) if (tw == CON_SETPLAYERVAR)
Gv_SetVar(lVar1, Gv_GetVarX(lVar2), vm.spriteNum, playerNum); Gv_SetVar(lVar1, Gv_GetVarX(lVar2), vm.spriteNum, playerNum);
@ -2451,11 +2445,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const labelNum = *insptr++; int const labelNum = *insptr++;
auto const &actorLabel = ActorLabels[labelNum]; auto const &actorLabel = ActorLabels[labelNum];
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
VM_SetStruct(actorLabel.flags, (intptr_t *)((char *)&actor[spriteNum] + actorLabel.offset), Gv_GetVarX(*insptr++)); VM_SetStruct(actorLabel.flags, (intptr_t *)((char *)&actor[spriteNum] + actorLabel.offset), Gv_GetVarX(*insptr++));
dispatch(); dispatch();
@ -2468,11 +2458,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const labelNum = *insptr++; int const labelNum = *insptr++;
auto const &actorLabel = ActorLabels[labelNum]; auto const &actorLabel = ActorLabels[labelNum];
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
Gv_SetVarX(*insptr++, VM_GetStruct(actorLabel.flags, (intptr_t *)((char *)&actor[spriteNum] + actorLabel.offset))); Gv_SetVarX(*insptr++, VM_GetStruct(actorLabel.flags, (intptr_t *)((char *)&actor[spriteNum] + actorLabel.offset)));
dispatch(); dispatch();
@ -2485,11 +2471,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const labelNum = *insptr++; int const labelNum = *insptr++;
auto const &spriteLabel = ActorLabels[labelNum]; auto const &spriteLabel = ActorLabels[labelNum];
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
VM_SetStruct(spriteLabel.flags, (intptr_t *)((char *)&sprite[spriteNum] + spriteLabel.offset), Gv_GetVarX(*insptr++)); VM_SetStruct(spriteLabel.flags, (intptr_t *)((char *)&sprite[spriteNum] + spriteLabel.offset), Gv_GetVarX(*insptr++));
dispatch(); dispatch();
@ -2502,11 +2484,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const labelNum = *insptr++; int const labelNum = *insptr++;
auto const &spriteLabel = ActorLabels[labelNum]; auto const &spriteLabel = ActorLabels[labelNum];
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
Gv_SetVarX(*insptr++, VM_GetStruct(spriteLabel.flags, (intptr_t *)((char *)&sprite[spriteNum] + spriteLabel.offset))); Gv_SetVarX(*insptr++, VM_GetStruct(spriteLabel.flags, (intptr_t *)((char *)&sprite[spriteNum] + spriteLabel.offset)));
dispatch(); dispatch();
@ -2518,11 +2496,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const labelNum = *insptr++; int const labelNum = *insptr++;
auto const &spriteExtLabel = ActorLabels[labelNum]; auto const &spriteExtLabel = ActorLabels[labelNum];
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
VM_SetStruct(spriteExtLabel.flags, (intptr_t *)((char *)&spriteext[spriteNum] + spriteExtLabel.offset), Gv_GetVarX(*insptr++)); VM_SetStruct(spriteExtLabel.flags, (intptr_t *)((char *)&spriteext[spriteNum] + spriteExtLabel.offset), Gv_GetVarX(*insptr++));
dispatch(); dispatch();
@ -2535,11 +2509,7 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/)
int const labelNum = *insptr++; int const labelNum = *insptr++;
auto const &spriteExtLabel = ActorLabels[labelNum]; auto const &spriteExtLabel = ActorLabels[labelNum];
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
Gv_SetVarX(*insptr++, VM_GetStruct(spriteExtLabel.flags, (intptr_t *)((char *)&spriteext[spriteNum] + spriteExtLabel.offset))); Gv_SetVarX(*insptr++, VM_GetStruct(spriteExtLabel.flags, (intptr_t *)((char *)&spriteext[spriteNum] + spriteExtLabel.offset)));
dispatch(); dispatch();
@ -2856,8 +2826,23 @@ badindex:
dispatch(); dispatch();
} }
vInstruction(CON_IFCANSHOOTTARGET): vInstruction(CON_IFCANSHOOTTARGET):
{ {
#define CHECK(x) \
if ((unsigned)x < MAXSPRITES && sprite[x].picnum == vm.pSprite->picnum) \
{ \
VM_CONDITIONAL(0); \
dispatch(); \
}
#define CHECK2(x) \
do \
{ \
vm.pSprite->ang += x; \
tw = A_CheckHitSprite(vm.spriteNum, &temphit); \
vm.pSprite->ang -= x; \
} while (0)
if (vm.playerDist > 1024) if (vm.playerDist > 1024)
{ {
int16_t temphit; int16_t temphit;
@ -2877,19 +2862,6 @@ badindex:
angDiff = 48; angDiff = 48;
} }
#define CHECK(x) \
if (x >= 0 && sprite[x].picnum == vm.pSprite->picnum) \
{ \
VM_CONDITIONAL(0); \
dispatch(); \
}
#define CHECK2(x) \
do \
{ \
vm.pSprite->ang += x; \
tw = A_CheckHitSprite(vm.spriteNum, &temphit); \
vm.pSprite->ang -= x; \
} while (0)
if (tw > dist) if (tw > dist)
{ {
@ -2911,11 +2883,10 @@ badindex:
} }
} }
VM_CONDITIONAL(1); VM_CONDITIONAL(1);
}
dispatch();
#undef CHECK #undef CHECK
#undef CHECK2 #undef CHECK2
}
dispatch();
vInstruction(CON_IFCANSEETARGET): vInstruction(CON_IFCANSEETARGET):
tw = cansee(vm.pSprite->x, vm.pSprite->y, vm.pSprite->z - ((krand() & 41) << 8), vm.pSprite->sectnum, vm.pPlayer->pos.x, vm.pPlayer->pos.y, tw = cansee(vm.pSprite->x, vm.pSprite->y, vm.pSprite->z - ((krand() & 41) << 8), vm.pSprite->sectnum, vm.pPlayer->pos.x, vm.pPlayer->pos.y,
@ -3243,11 +3214,7 @@ badindex:
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
int const soundNum = Gv_GetVarX(*insptr++); int const soundNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum >= MAXSOUNDS)) VM_ASSERT((unsigned)soundNum < MAXSOUNDS, "invalid sound %d\n", soundNum);
{
CON_ERRPRINTF("invalid sound %d\n", soundNum);
abort_after_error();
}
insptr--; insptr--;
VM_CONDITIONAL(A_CheckSoundPlaying(spriteNum, soundNum)); VM_CONDITIONAL(A_CheckSoundPlaying(spriteNum, soundNum));
@ -3270,11 +3237,7 @@ badindex:
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
int const soundNum = Gv_GetVarX(*insptr++); int const soundNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum >= MAXSOUNDS)) VM_ASSERT((unsigned)soundNum < MAXSOUNDS, "invalid sound %d\n", soundNum);
{
CON_ERRPRINTF("invalid sound %d\n", soundNum);
abort_after_error();
}
if (A_CheckSoundPlaying(spriteNum, soundNum)) if (A_CheckSoundPlaying(spriteNum, soundNum))
S_StopEnvSound(soundNum, spriteNum); S_StopEnvSound(soundNum, spriteNum);
@ -3288,11 +3251,7 @@ badindex:
int const spriteNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(insptr[-1]) : vm.spriteNum; int const spriteNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(insptr[-1]) : vm.spriteNum;
int const soundNum = Gv_GetVarX(*insptr++); int const soundNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum >= MAXSOUNDS)) VM_ASSERT((unsigned)soundNum < MAXSOUNDS, "invalid sound %d\n", soundNum);
{
CON_ERRPRINTF("invalid sound %d\n", soundNum);
abort_after_error();
}
A_PlaySound(soundNum, spriteNum); A_PlaySound(soundNum, spriteNum);
@ -3306,11 +3265,7 @@ badindex:
int const soundNum = Gv_GetVarX(*insptr++); int const soundNum = Gv_GetVarX(*insptr++);
int const newPitch = Gv_GetVarX(*insptr++); int const newPitch = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum >= MAXSOUNDS)) VM_ASSERT((unsigned)soundNum < MAXSOUNDS, "invalid sound %d\n", soundNum);
{
CON_ERRPRINTF("invalid sound %d\n", soundNum);
abort_after_error();
}
S_ChangeSoundPitch(soundNum, spriteNum, newPitch); S_ChangeSoundPitch(soundNum, spriteNum, newPitch);
@ -3523,11 +3478,8 @@ badindex:
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
int const clipType = Gv_GetVarX(*insptr++); int const clipType = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
A_SetSprite(spriteNum, clipType); A_SetSprite(spriteNum, clipType);
dispatch(); dispatch();
} }
@ -3538,11 +3490,8 @@ badindex:
int const sectNum = Gv_GetVarX(*insptr++); int const sectNum = Gv_GetVarX(*insptr++);
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)sectNum >= (unsigned)numsectors)) VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
{
CON_ERRPRINTF("invalid sector %d\n", sectNum);
abort_after_error();
}
G_ActivateBySector(sectNum, spriteNum); G_ActivateBySector(sectNum, spriteNum);
dispatch(); dispatch();
} }
@ -3553,11 +3502,8 @@ badindex:
int const sectNum = Gv_GetVarX(*insptr++); int const sectNum = Gv_GetVarX(*insptr++);
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)sectNum >= (unsigned)numsectors)) VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
{
CON_ERRPRINTF("invalid sector %d\n", sectNum);
abort_after_error();
}
G_OperateSectors(sectNum, spriteNum); G_OperateSectors(sectNum, spriteNum);
dispatch(); dispatch();
} }
@ -3568,11 +3514,8 @@ badindex:
int const nTag = Gv_GetVarX(*insptr++); int const nTag = Gv_GetVarX(*insptr++);
int const playerNum = (*insptr++ == g_thisActorVarID) ? vm.playerNum : Gv_GetVarX(insptr[-1]); int const playerNum = (*insptr++ == g_thisActorVarID) ? vm.playerNum : Gv_GetVarX(insptr[-1]);
if (EDUKE32_PREDICT_FALSE((unsigned)playerNum >= (unsigned)g_mostConcurrentPlayers)) VM_ASSERT((unsigned)playerNum < (unsigned)g_mostConcurrentPlayers, "invalid player %d\n", playerNum);
{
CON_ERRPRINTF("invalid player %d\n", playerNum);
abort_after_error();
}
G_OperateActivators(nTag, playerNum); G_OperateActivators(nTag, playerNum);
dispatch(); dispatch();
} }
@ -3623,11 +3566,7 @@ badindex:
int const gameVar = *insptr++; int const gameVar = *insptr++;
int const quoteNum = Gv_GetVarX(*insptr++); int const quoteNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE(apStrings[quoteNum] == NULL)) VM_ASSERT((unsigned)quoteNum < MAXQUOTES && apStrings[quoteNum], "invalid quote %d\n", quoteNum);
{
CON_ERRPRINTF("null quote %d\n", quoteNum);
abort_after_error();
}
Gv_SetVarX(gameVar, Bstrlen(apStrings[quoteNum])); Gv_SetVarX(gameVar, Bstrlen(apStrings[quoteNum]));
dispatch(); dispatch();
@ -3688,11 +3627,7 @@ badindex:
int const gameVar = *insptr++; int const gameVar = *insptr++;
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
Gv_SetVarX(gameVar, prevspritestat[spriteNum]); Gv_SetVarX(gameVar, prevspritestat[spriteNum]);
dispatch(); dispatch();
@ -3704,11 +3639,7 @@ badindex:
int const gameVar = *insptr++; int const gameVar = *insptr++;
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
Gv_SetVarX(gameVar, nextspritestat[spriteNum]); Gv_SetVarX(gameVar, nextspritestat[spriteNum]);
dispatch(); dispatch();
@ -3720,11 +3651,7 @@ badindex:
int const gameVar = *insptr++; int const gameVar = *insptr++;
int const sectNum = Gv_GetVarX(*insptr++); int const sectNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)sectNum >= (unsigned)numsectors)) VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
{
CON_ERRPRINTF("invalid sector %d\n", sectNum);
abort_after_error();
}
Gv_SetVarX(gameVar, headspritesect[sectNum]); Gv_SetVarX(gameVar, headspritesect[sectNum]);
dispatch(); dispatch();
@ -3736,11 +3663,7 @@ badindex:
int const gameVar = *insptr++; int const gameVar = *insptr++;
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
Gv_SetVarX(gameVar, prevspritesect[spriteNum]); Gv_SetVarX(gameVar, prevspritesect[spriteNum]);
dispatch(); dispatch();
@ -3752,11 +3675,7 @@ badindex:
int const gameVar = *insptr++; int const gameVar = *insptr++;
int const spriteNum = Gv_GetVarX(*insptr++); int const spriteNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", spriteNum);
abort_after_error();
}
Gv_SetVarX(gameVar, nextspritesect[spriteNum]); Gv_SetVarX(gameVar, nextspritesect[spriteNum]);
dispatch(); dispatch();
@ -3769,27 +3688,17 @@ badindex:
int const gameFunc = Gv_GetVarX(*insptr++); int const gameFunc = Gv_GetVarX(*insptr++);
int const funcPos = Gv_GetVarX(*insptr++); int const funcPos = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)quoteIndex >= MAXQUOTES || apStrings[quoteIndex] == NULL)) VM_ASSERT((unsigned)quoteIndex < MAXQUOTES && apStrings[quoteIndex], "invalid quote %d\n", quoteIndex);
{ VM_ASSERT((unsigned)gameFunc < NUMGAMEFUNCTIONS, "invalid function %d\n", gameFunc);
CON_ERRPRINTF("invalid quote %d\n", quoteIndex);
abort_after_error(); if (funcPos < 2)
} Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][funcPos]));
else if (EDUKE32_PREDICT_FALSE((unsigned)gameFunc >= NUMGAMEFUNCTIONS))
{
CON_ERRPRINTF("invalid function %d\n", gameFunc);
abort_after_error();
}
else else
{ {
if (funcPos < 2) Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][0]));
Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][funcPos]));
else
{
Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][0]));
if (!*tempbuf) if (!*tempbuf)
Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][1])); Bstrcpy(tempbuf, KB_ScanCodeToString(ud.config.KeyboardKeys[gameFunc][1]));
}
} }
if (*tempbuf) if (*tempbuf)
@ -3879,22 +3788,14 @@ badindex:
switch (tw) switch (tw)
{ {
case CON_GETPNAME: case CON_GETPNAME:
if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES || apStrings[q] == NULL)) VM_ASSERT((unsigned)q < MAXQUOTES && apStrings[q], "invalid quote %d\n", q);
{
CON_ERRPRINTF("invalid quote %d\n", q);
abort_after_error();
}
if (g_player[j].user_name[0]) if (g_player[j].user_name[0])
Bstrcpy(apStrings[q], g_player[j].user_name); Bstrcpy(apStrings[q], g_player[j].user_name);
else else
Bsprintf(apStrings[q], "%d", j); Bsprintf(apStrings[q], "%d", j);
break; break;
case CON_QGETSYSSTR: case CON_QGETSYSSTR:
if (EDUKE32_PREDICT_FALSE((unsigned)q >= MAXQUOTES || apStrings[q] == NULL)) VM_ASSERT((unsigned)q < MAXQUOTES && apStrings[q], "invalid quote %d\n", q);
{
CON_ERRPRINTF("invalid quote %d\n", q);
abort_after_error();
}
switch (j) switch (j)
{ {
case STR_MAPNAME: case STR_MAPNAME:
@ -3922,11 +3823,7 @@ badindex:
break; break;
} }
case STR_PLAYERNAME: case STR_PLAYERNAME:
if (EDUKE32_PREDICT_FALSE((unsigned)vm.playerNum >= (unsigned)g_mostConcurrentPlayers)) VM_ASSERT((unsigned)vm.playerNum < (unsigned)g_mostConcurrentPlayers, "invalid player %d\n", vm.playerNum);
{
CON_ERRPRINTF("invalid player %d\n", vm.playerNum);
abort_after_error();
}
Bstrcpy(apStrings[q], g_player[vm.playerNum].user_name); Bstrcpy(apStrings[q], g_player[vm.playerNum].user_name);
break; break;
case STR_VERSION: case STR_VERSION:
@ -4196,11 +4093,7 @@ badindex:
{ {
int const tileNum = Gv_GetVarX(*insptr++); int const tileNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) VM_ASSERT((unsigned)vm.pSprite->sectnum < MAXSECTORS, "invalid sector %d\n", vm.pUSprite->sectnum);
{
CON_ERRPRINTF("invalid sector %d\n", vm.pUSprite->sectnum);
abort_after_error();
}
int const spriteNum = A_Spawn(vm.spriteNum, tileNum); int const spriteNum = A_Spawn(vm.spriteNum, tileNum);
@ -4225,11 +4118,7 @@ badindex:
{ {
int j = Gv_GetVarX(*insptr++); int j = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) VM_ASSERT((unsigned)vm.pSprite->sectnum < MAXSECTORS, "invalid sector %d\n", vm.pUSprite->sectnum);
{
CON_ERRPRINTF("invalid sector %d\n", vm.pUSprite->sectnum);
abort_after_error();
}
j = A_Shoot(vm.spriteNum, j); j = A_Shoot(vm.spriteNum, j);
@ -4246,11 +4135,7 @@ badindex:
int const zvel = (int16_t)Gv_GetVarX(*insptr++); int const zvel = (int16_t)Gv_GetVarX(*insptr++);
int j = Gv_GetVarX(*insptr++); int j = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= (unsigned)numsectors)) VM_ASSERT((unsigned)vm.pSprite->sectnum < MAXSECTORS, "invalid sector %d\n", vm.pUSprite->sectnum);
{
CON_ERRPRINTF("invalid sector %d\n", vm.pUSprite->sectnum);
abort_after_error();
}
j = A_ShootWithZvel(vm.spriteNum, j, zvel); j = A_ShootWithZvel(vm.spriteNum, j, zvel);
@ -4274,11 +4159,7 @@ badindex:
{ {
int const soundNum = Gv_GetVarX(*insptr++); int const soundNum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)soundNum >= MAXSOUNDS)) VM_ASSERT((unsigned)soundNum < MAXSOUNDS, "invalid sound %d\n", soundNum);
{
CON_ERRPRINTF("invalid sound %d\n", soundNum);
abort_after_error();
}
switch (tw) switch (tw)
{ {
@ -4305,11 +4186,7 @@ badindex:
{ {
int const nQuote = Gv_GetVarX(*insptr++); int const nQuote = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)nQuote >= MAXQUOTES || apStrings[nQuote] == NULL)) VM_ASSERT((unsigned)nQuote < MAXQUOTES && apStrings[nQuote], "invalid quote %d\n", nQuote);
{
CON_ERRPRINTF("invalid quote %d for anim!\n", nQuote);
abort_after_error();
}
if (tw == CON_IFCUTSCENE) if (tw == CON_IFCUTSCENE)
{ {
@ -4387,11 +4264,7 @@ badindex:
abort_after_error(); abort_after_error();
} }
if (EDUKE32_PREDICT_FALSE((unsigned)v.params[2] >= (unsigned)numsectors)) VM_ASSERT((unsigned)v.params[2] < MAXSECTORS, "invalid sector %d\n", v.params[2]);
{
CON_ERRPRINTF("invalid sector %d\n", v.params[2]);
dispatch();
}
if (tw != CON_SHOWVIEWQ16 && tw != CON_SHOWVIEWQ16UNBIASED) if (tw != CON_SHOWVIEWQ16 && tw != CON_SHOWVIEWQ16UNBIASED)
{ {
@ -4464,11 +4337,7 @@ badindex:
abort_after_error(); abort_after_error();
} }
if (EDUKE32_PREDICT_FALSE((unsigned)v.nQuote >= MAXQUOTES || apStrings[v.nQuote] == NULL)) VM_ASSERT((unsigned)v.nQuote < MAXQUOTES && apStrings[v.nQuote], "invalid quote %d\n", v.nQuote);
{
CON_ERRPRINTF("invalid quote %d\n", v.nQuote);
abort_after_error();
}
G_PrintGameText(v.tilenum, v.pos.x >> 1, v.pos.y, apStrings[v.nQuote], v.shade, v.pal, v.orientation & (ROTATESPRITE_MAX - 1), G_PrintGameText(v.tilenum, v.pos.x >> 1, v.pos.y, apStrings[v.nQuote], v.shade, v.pal, v.orientation & (ROTATESPRITE_MAX - 1),
v.bound[0].x, v.bound[0].y, v.bound[1].x, v.bound[1].y, z, 0); v.bound[0].x, v.bound[0].y, v.bound[1].x, v.bound[1].y, z, 0);
@ -4512,11 +4381,7 @@ badindex:
} v; } v;
Gv_FillWithVars(v); Gv_FillWithVars(v);
if (EDUKE32_PREDICT_FALSE((unsigned)v.nQuote >= MAXQUOTES || apStrings[v.nQuote] == NULL)) VM_ASSERT((unsigned)v.nQuote < MAXQUOTES && apStrings[v.nQuote], "invalid quote %d\n", v.nQuote);
{
CON_ERRPRINTF("invalid quote %d\n", v.nQuote);
abort_after_error();
}
minitextshade(v.pos.x, v.pos.y, apStrings[v.nQuote], v.shade, v.pal, 2 + 8 + 16); minitextshade(v.pos.x, v.pos.y, apStrings[v.nQuote], v.shade, v.pal, 2 + 8 + 16);
dispatch(); dispatch();
@ -4542,11 +4407,7 @@ badindex:
abort_after_error(); abort_after_error();
} }
if (EDUKE32_PREDICT_FALSE((unsigned)v.nQuote >= MAXQUOTES || apStrings[v.nQuote] == NULL)) VM_ASSERT((unsigned)v.nQuote < MAXQUOTES && apStrings[v.nQuote], "invalid quote %d\n", v.nQuote);
{
CON_ERRPRINTF("invalid quote %d\n", v.nQuote);
abort_after_error();
}
G_ScreenText(v.tilenum, v.v.x, v.v.y, v.v.z, v.blockangle, v.charangle, apStrings[v.nQuote], v.shade, v.pal, G_ScreenText(v.tilenum, v.v.x, v.v.y, v.v.z, v.blockangle, v.charangle, apStrings[v.nQuote], v.shade, v.pal,
2 | (v.orientation & (ROTATESPRITE_MAX - 1)), v.alpha, v.spacing.x, v.spacing.y, v.between.x, v.between.y, v.nFlags, 2 | (v.orientation & (ROTATESPRITE_MAX - 1)), v.alpha, v.spacing.x, v.spacing.y, v.between.x, v.between.y, v.nFlags,
@ -4575,11 +4436,7 @@ badindex:
} v2; } v2;
Gv_FillWithVars(v2); Gv_FillWithVars(v2);
if (EDUKE32_PREDICT_FALSE((unsigned)v.sectNum >= (unsigned)numsectors)) VM_ASSERT((unsigned)v.sectNum < MAXSECTORS, "invalid sector %d\n", v.sectNum);
{
CON_ERRPRINTF("invalid sector %d\n", v.sectNum);
abort_after_error();
}
int32_t ceilz, ceilhit, florz, florhit; int32_t ceilz, ceilhit, florz, florhit;
@ -4598,11 +4455,7 @@ badindex:
{ {
int const sectnum = Gv_GetVarX(*insptr++); int const sectnum = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)sectnum >= (unsigned)numsectors)) VM_ASSERT((unsigned)sectnum < MAXSECTORS, "invalid sector %d\n", sectnum);
{
CON_ERRPRINTF("invalid sector %d\n", sectnum);
abort_after_error();
}
if (tw == CON_SECTSETINTERPOLATION) if (tw == CON_SECTSETINTERPOLATION)
Sect_SetInterpolation(sectnum); Sect_SetInterpolation(sectnum);
@ -4687,11 +4540,7 @@ badindex:
Gv_FillWithVars(v); Gv_FillWithVars(v);
int16_t sectNum = v.sectNum32; int16_t sectNum = v.sectNum32;
if (EDUKE32_PREDICT_FALSE((unsigned)sectNum >= (unsigned)numsectors)) VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum);
{
CON_ERRPRINTF("invalid sector %d\n", sectNum);
abort_after_error();
}
Gv_SetVarX( Gv_SetVarX(
returnVar, returnVar,
@ -4722,11 +4571,7 @@ badindex:
int const zReturn = *insptr++; int const zReturn = *insptr++;
int const clipType = Gv_GetVarX(*insptr++); int const clipType = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)v.sectnum >= (unsigned)numsectors)) VM_ASSERT((unsigned)v.sectnum < MAXSECTORS, "invalid sector %d\n", v.sectnum);
{
CON_ERRPRINTF("invalid sector %d\n", v.sectnum);
abort_after_error();
}
hitdata_t hit; hitdata_t hit;
hitscan(&v.origin, v.sectnum, v.vect.x, v.vect.y, v.vect.z, &hit, clipType); hitscan(&v.origin, v.sectnum, v.vect.x, v.vect.y, v.vect.z, &hit, clipType);
@ -4814,11 +4659,7 @@ badindex:
} v2; } v2;
Gv_FillWithVars(v2); Gv_FillWithVars(v2);
if (EDUKE32_PREDICT_FALSE((unsigned)v.sectNum >= (unsigned)numsectors)) VM_ASSERT((unsigned)v.sectNum < MAXSECTORS, "invalid sector %d\n", v.sectNum);
{
CON_ERRPRINTF("Invalid sector %d\n", v.sectNum);
abort_after_error();
}
int16_t neartagsector, neartagwall, neartagsprite; int16_t neartagsector, neartagwall, neartagsprite;
int32_t neartaghitdist; int32_t neartaghitdist;
@ -4856,11 +4697,7 @@ badindex:
} v; } v;
Gv_FillWithVars(v); Gv_FillWithVars(v);
if (EDUKE32_PREDICT_FALSE((unsigned)v.spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)v.spriteNum < MAXSPRITES, "invalid sprite %d\n", v.spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", v.spriteNum);
abort_after_error();
}
Gv_SetVarX(*insptr++, A_MoveSprite(v.spriteNum, &v.vect, v.clipType)); Gv_SetVarX(*insptr++, A_MoveSprite(v.spriteNum, &v.vect, v.clipType));
dispatch(); dispatch();
@ -4876,11 +4713,8 @@ badindex:
} v; } v;
Gv_FillWithVars(v); Gv_FillWithVars(v);
if (EDUKE32_PREDICT_FALSE((unsigned)v.spriteNum >= MAXSPRITES)) VM_ASSERT((unsigned)v.spriteNum < MAXSPRITES, "invalid sprite %d\n", v.spriteNum);
{
CON_ERRPRINTF("invalid sprite %d\n", v.spriteNum);
abort_after_error();
}
setsprite(v.spriteNum, &v.vect); setsprite(v.spriteNum, &v.vect);
dispatch(); dispatch();
} }
@ -4896,11 +4730,8 @@ badindex:
} v; } v;
Gv_FillWithVars(v); Gv_FillWithVars(v);
if (EDUKE32_PREDICT_FALSE((unsigned)v.sectNum >= (unsigned)numsectors)) VM_ASSERT((unsigned)v.sectNum < MAXSECTORS, "invalid sector %d\n", v.sectNum);
{
CON_ERRPRINTF("invalid sector %d\n", v.sectNum);
abort_after_error();
}
Gv_SetVarX(*insptr++, (tw == CON_GETFLORZOFSLOPE ? getflorzofslope : getceilzofslope)(v.sectNum, v.vect.x, v.vect.y)); Gv_SetVarX(*insptr++, (tw == CON_GETFLORZOFSLOPE ? getflorzofslope : getceilzofslope)(v.sectNum, v.vect.x, v.vect.y));
dispatch(); dispatch();
} }
@ -4941,11 +4772,9 @@ badindex:
vInstruction(CON_SPAWN): vInstruction(CON_SPAWN):
insptr++; insptr++;
if ((unsigned)vm.pSprite->sectnum >= MAXSECTORS)
{ VM_ASSERT((unsigned)vm.pSprite->sectnum < MAXSECTORS, "invalid sector %d\n", vm.pUSprite->sectnum);
CON_ERRPRINTF("invalid sector %d\n", vm.pUSprite->sectnum);
abort_after_error();
}
A_Spawn(vm.spriteNum, *insptr++); A_Spawn(vm.spriteNum, *insptr++);
dispatch(); dispatch();
@ -5202,12 +5031,7 @@ badindex:
vInstruction(CON_PALFROM): vInstruction(CON_PALFROM):
insptr++; insptr++;
if (EDUKE32_PREDICT_FALSE((unsigned)vm.playerNum >= (unsigned)g_mostConcurrentPlayers)) VM_ASSERT((unsigned)vm.playerNum < (unsigned)g_mostConcurrentPlayers, "invalid player %d\n", vm.playerNum);
{
CON_ERRPRINTF("invalid player %d\n", vm.playerNum);
abort_after_error();
}
else
{ {
palette_t const pal = { uint8_t(insptr[1]), uint8_t(insptr[2]), uint8_t(insptr[3]), uint8_t(insptr[0]) }; palette_t const pal = { uint8_t(insptr[1]), uint8_t(insptr[2]), uint8_t(insptr[3]), uint8_t(insptr[0]) };
insptr += 4; insptr += 4;
@ -5662,11 +5486,7 @@ badindex:
insptr++; insptr++;
int const playerNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(*insptr) : vm.playerNum; int const playerNum = (*insptr++ != g_thisActorVarID) ? Gv_GetVarX(*insptr) : vm.playerNum;
if (EDUKE32_PREDICT_FALSE((unsigned)playerNum >= (unsigned)g_mostConcurrentPlayers)) VM_ASSERT((unsigned)playerNum < (unsigned)g_mostConcurrentPlayers, "invalid player %d\n", playerNum);
{
CON_ERRPRINTF("invalid player %d\n", (int)playerNum);
abort_after_error();
}
if (tw == CON_CHECKAVAILWEAPON) if (tw == CON_CHECKAVAILWEAPON)
P_CheckWeapon(g_player[playerNum].ps); P_CheckWeapon(g_player[playerNum].ps);
@ -5755,11 +5575,7 @@ badindex:
int const arrayNum = *insptr++; int const arrayNum = *insptr++;
int const quoteFilename = *insptr++; int const quoteFilename = *insptr++;
if (EDUKE32_PREDICT_FALSE(apStrings[quoteFilename] == NULL)) VM_ASSERT((unsigned)quoteFilename < MAXQUOTES && apStrings[quoteFilename], "invalid quote %d\n", quoteFilename);
{
CON_ERRPRINTF("null quote %d\n", quoteFilename);
abort_after_error();
}
buildvfs_kfd kFile = kopen4loadfrommod(apStrings[quoteFilename], 0); buildvfs_kfd kFile = kopen4loadfrommod(apStrings[quoteFilename], 0);
@ -5828,11 +5644,7 @@ badindex:
int const arrayNum = *insptr++; int const arrayNum = *insptr++;
int const quoteFilename = *insptr++; int const quoteFilename = *insptr++;
if (EDUKE32_PREDICT_FALSE(apStrings[quoteFilename] == NULL)) VM_ASSERT((unsigned)quoteFilename < MAXQUOTES && apStrings[quoteFilename], "invalid quote %d\n", quoteFilename);
{
CON_ERRPRINTF("null quote %d\n", quoteFilename);
abort_after_error();
}
char temp[BMAX_PATH]; char temp[BMAX_PATH];
@ -6349,11 +6161,7 @@ badindex:
vInstruction(CON_QUOTE): vInstruction(CON_QUOTE):
insptr++; insptr++;
if (EDUKE32_PREDICT_FALSE((unsigned)vm.playerNum >= MAXPLAYERS)) VM_ASSERT((unsigned)vm.playerNum < (unsigned)g_mostConcurrentPlayers, "invalid player %d\n", vm.playerNum);
{
CON_ERRPRINTF("invalid player %d\n", vm.playerNum);
abort_after_error();
}
P_DoQuote(*(insptr++) | MAXQUOTES, vm.pPlayer); P_DoQuote(*(insptr++) | MAXQUOTES, vm.pPlayer);
dispatch(); dispatch();
@ -6362,11 +6170,7 @@ badindex:
insptr++; insptr++;
tw = Gv_GetVarX(*insptr++); tw = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)tw >= MAXQUOTES || apStrings[tw] == NULL)) VM_ASSERT((unsigned)tw < MAXQUOTES && apStrings[tw], "invalid quote %d\n", (int)tw);
{
CON_ERRPRINTF("invalid quote %d\n", (int)tw);
abort_after_error();
}
G_AddUserQuote(apStrings[tw]); G_AddUserQuote(apStrings[tw]);
dispatch(); dispatch();
@ -6375,11 +6179,7 @@ badindex:
insptr++; insptr++;
tw = Gv_GetVarX(*insptr++); tw = Gv_GetVarX(*insptr++);
if (EDUKE32_PREDICT_FALSE((unsigned)tw >= MAXQUOTES || apStrings[tw] == NULL)) VM_ASSERT((unsigned)tw < MAXQUOTES && apStrings[tw], "invalid quote %d\n", (int)tw);
{
CON_ERRPRINTF("invalid quote %d\n", (int)tw);
abort_after_error();
}
OSD_Printf("%s\n", apStrings[tw]); OSD_Printf("%s\n", apStrings[tw]);
dispatch(); dispatch();