Merge branch 'no-snull' into 'master'

SOC/Lua null struct safety

Closes #1488

See merge request KartKrew/Kart!2469
This commit is contained in:
Sal 2024-10-05 15:26:06 +00:00
commit 39a0724db6
2 changed files with 12 additions and 10 deletions

View file

@ -378,7 +378,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
{ {
if (i == 0 && word2[0] != '0') // If word2 isn't a number if (i == 0 && word2[0] != '0') // If word2 isn't a number
i = get_state(word2); // find a state by name i = get_state(word2); // find a state by name
if (i < NUMSTATES && i >= 0) if (i < NUMSTATES && i > 0)
{ {
if (i < (S_FIRSTFREESLOT+freeslotusage[0][1])) if (i < (S_FIRSTFREESLOT+freeslotusage[0][1]))
{ {
@ -389,7 +389,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile)
} }
else else
{ {
deh_warning("Frame %d out of range (0 - %d)", i, NUMSTATES-1); deh_warning("Frame %d out of range (1 - %d)", i, NUMSTATES-1);
ignorelines(f); ignorelines(f);
} }
} }

View file

@ -730,8 +730,8 @@ static int lib_getState(lua_State *L)
lua_remove(L, 1); lua_remove(L, 1);
i = luaL_checkinteger(L, 1); i = luaL_checkinteger(L, 1);
if (i >= NUMSTATES) if (i == 0 || i >= NUMSTATES)
return luaL_error(L, "states[] index %d out of range (0 - %d)", i, NUMSTATES-1); return luaL_error(L, "states[] index %d out of range (1 - %d)", i, NUMSTATES-1);
LUA_PushUserdata(L, &states[i], META_STATE); LUA_PushUserdata(L, &states[i], META_STATE);
return 1; return 1;
} }
@ -743,8 +743,8 @@ static int lib_setState(lua_State *L)
lua_remove(L, 1); // don't care about states[] userdata. lua_remove(L, 1); // don't care about states[] userdata.
{ {
UINT32 i = luaL_checkinteger(L, 1); UINT32 i = luaL_checkinteger(L, 1);
if (i >= NUMSTATES) if (i == 0 || i >= NUMSTATES)
return luaL_error(L, "states[] index %d out of range (0 - %d)", i, NUMSTATES-1); return luaL_error(L, "states[] index %d out of range (1 - %d)", i, NUMSTATES-1);
state = &states[i]; // get the state to assign to. state = &states[i]; // get the state to assign to.
} }
luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table. luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table.
@ -1092,8 +1092,8 @@ static int lib_getMobjInfo(lua_State *L)
lua_remove(L, 1); lua_remove(L, 1);
i = luaL_checkinteger(L, 1); i = luaL_checkinteger(L, 1);
if (i >= NUMMOBJTYPES) if (i == 0 || i >= NUMMOBJTYPES)
return luaL_error(L, "mobjinfo[] index %d out of range (0 - %d)", i, NUMMOBJTYPES-1); return luaL_error(L, "mobjinfo[] index %d out of range (1 - %d)", i, NUMMOBJTYPES-1);
LUA_PushUserdata(L, &mobjinfo[i], META_MOBJINFO); LUA_PushUserdata(L, &mobjinfo[i], META_MOBJINFO);
return 1; return 1;
} }
@ -1105,8 +1105,8 @@ static int lib_setMobjInfo(lua_State *L)
lua_remove(L, 1); // don't care about mobjinfo[] userdata. lua_remove(L, 1); // don't care about mobjinfo[] userdata.
{ {
UINT32 i = luaL_checkinteger(L, 1); UINT32 i = luaL_checkinteger(L, 1);
if (i >= NUMMOBJTYPES) if (i == 0 || i >= NUMMOBJTYPES)
return luaL_error(L, "mobjinfo[] index %d out of range (0 - %d)", i, NUMMOBJTYPES-1); return luaL_error(L, "mobjinfo[] index %d out of range (1 - %d)", i, NUMMOBJTYPES-1);
info = &mobjinfo[i]; // get the mobjinfo to assign to. info = &mobjinfo[i]; // get the mobjinfo to assign to.
} }
luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table. luaL_checktype(L, 2, LUA_TTABLE); // check that we've been passed a table.
@ -1355,6 +1355,8 @@ static int mobjinfo_set(lua_State *L)
info->flags = (INT32)luaL_checkinteger(L, 3); info->flags = (INT32)luaL_checkinteger(L, 3);
else if (fastcmp(field,"raisestate")) else if (fastcmp(field,"raisestate"))
info->raisestate = luaL_checkinteger(L, 3); info->raisestate = luaL_checkinteger(L, 3);
else if (fastcmp(field,"string"))
return luaL_error(L, LUA_QL("mobjinfo_t") " field " LUA_QS " should not be set directly.", field);
else { else {
lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS);
I_Assert(lua_istable(L, -1)); I_Assert(lua_istable(L, -1));