Skip to content

Commit f63bbd4

Browse files
authored
Fix a crash in Spring.GetProfilerTimeRecord (beyond-all-reason#3172)
No table was pushed, so `lua_rawset(L, -3)` tried to dereference a float as a table and segfaulted.
1 parent d4a2111 commit f63bbd4

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

rts/Lua/LuaUnsyncedRead.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,23 +616,26 @@ int LuaUnsyncedRead::GetProfilerTimeRecord(lua_State* L)
616616
{
617617
const CTimeProfiler::TimeRecord& record = CTimeProfiler::GetInstance().GetTimeRecord(lua_tostring(L, 1));
618618

619-
int numRet = 5;
619+
const bool wantFrameData = luaL_optboolean(L, 2, false);
620+
620621
lua_pushnumber(L, record.total.toMilliSecsf());
621622
lua_pushnumber(L, record.current.toMilliSecsf());
622623
lua_pushnumber(L, record.stats.x); // max-dt
623624
lua_pushnumber(L, record.stats.y); // time-%
624625
lua_pushnumber(L, record.stats.z); // peak-%
625626

626-
if (luaL_optboolean(L, 2, false)) {
627-
for (size_t i = 0; i < record.frames.size(); i++) {
628-
lua_pushnumber(L, i + 1); // key
629-
lua_pushnumber(L, record.frames[i].toMilliSecsf()); // val
630-
lua_rawset(L, -3);
631-
}
632-
++numRet;
627+
if (!wantFrameData)
628+
return 5;
629+
630+
lua_createtable(L, record.frames.size(), 0);
631+
632+
for (size_t i = 0; i < record.frames.size(); i++) {
633+
lua_pushnumber(L, i + 1); // key
634+
lua_pushnumber(L, record.frames[i].toMilliSecsf()); // val
635+
lua_rawset(L, -3);
633636
}
634637

635-
return numRet;
638+
return 6;
636639
}
637640

638641
/***

0 commit comments

Comments
 (0)