add guards to smlua__iter lot types
Some checks are pending
Build coop / build-linux (push) Waiting to run
Build coop / build-steamos (push) Waiting to run
Build coop / build-windows (push) Waiting to run
Build coop / build-macos-arm (push) Waiting to run
Build coop / build-macos-intel (push) Waiting to run

Resolves #1257
This commit is contained in:
Isaac0-dev 2026-05-22 12:43:42 +10:00
parent 7ed28bf411
commit a8da02aae1

View file

@ -49,7 +49,14 @@ struct LuaObjectField* smlua_get_object_field_from_ot(struct LuaObjectTable* ot,
return NULL;
}
struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) {
bool smlua_valid_lot(u16 lot) {
if (lot > LOT_NONE && lot < LOT_MAX) { return true; }
if (lot > LOT_AUTOGEN_MIN && lot < LOT_AUTOGEN_MAX) { return true; }
return false;
}
struct LuaObjectField *smlua_get_object_field(u16 lot, const char* key) {
if (!smlua_valid_lot(lot)) { return NULL; }
if (lot > LOT_AUTOGEN_MIN) {
return smlua_get_object_field_autogen(lot, key);
}
@ -58,12 +65,6 @@ struct LuaObjectField* smlua_get_object_field(u16 lot, const char* key) {
return smlua_get_object_field_from_ot(ot, key);
}
bool smlua_valid_lot(u16 lot) {
if (lot > LOT_NONE && lot < LOT_MAX) { return true; }
if (lot > LOT_AUTOGEN_MIN && lot < LOT_AUTOGEN_MAX) { return true; }
return false;
}
bool smlua_valid_lvt(u16 lvt) {
return (lvt < LVT_MAX);
}
@ -684,11 +685,16 @@ int smlua__iter(lua_State *L) {
lua_rawgeti(L, 1, 2);
const CObject *cobj = lua_touserdata(L, -1);
lua_pop(L, 1);
// Only support autogen objects
if (cobj->lot <= LOT_AUTOGEN_MIN || cobj->lot >= LOT_AUTOGEN_MAX) {
return 0;
}
extern struct LuaObjectTable sLuaObjectAutogenTable[];
struct LuaObjectTable* ot = &sLuaObjectAutogenTable[cobj->lot - LOT_AUTOGEN_MIN - 1];
if (i >= ot->fieldCount) { return 0; }
u8* pointer = (u8*)(intptr_t) cobj->pointer;
struct LuaObjectField* data = &ot->fields[i];
lua_pushstring(L, data->key);