Skip to content

Commit

Permalink
Lua: Prevent crash when calling a CRT function with an invalid parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
brianferguson committed Jul 24, 2024
1 parent e79d15f commit 8a37186
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Library/lua/LuaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,16 @@ void LuaScript::RunString(const std::wstring& str)
// Pop table and set the environment of the loaded chunk to it
lua_setfenv(L, -2);

// Ignore any CRT invalid parameter exceptions (like os.date with an invalid format)
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
_CrtSetReportMode(_CRT_ASSERT, 0);

if (lua_pcall(L, 0, 0, 0))
{
LuaHelper::ReportErrors();
}

_set_invalid_parameter_handler(oldHandler);
}
}

Expand Down

0 comments on commit 8a37186

Please sign in to comment.