Skip to content

Commit 227db24

Browse files
committed
Avoid crash in gettable_upvalue_fast
1 parent 4451ac1 commit 227db24

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lvm.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,15 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
138138
}
139139

140140
void luaV_gettable_upvalue_fast (lua_State *L, const TValue *t, TValue *key, StkId val) {
141+
// if not a table, fallback to slow path
142+
// this is most likely (always?) because the table is nil; so this slow path
143+
// is most likely an error path
144+
if (!ttistable(t)) [[unlikely]] { return luaV_gettable(L, t, key, val); }
145+
141146
Table *h = hvalue(t);
142147
const TValue *res = luaH_get(h, key);
143148

144-
// lua_assert(!ttisnil(res) || /* result is not nil? */
145-
// (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL);
149+
lua_assert(!ttisnil(res) || fasttm(L, h->metatable, TM_INDEX) == nullptr);
146150

147151
setobj2s(L, val, res);
148152
}

0 commit comments

Comments
 (0)