lua: lua_tostring() on an error value can return NULL

Lua is so clever it allows values that can't be converted to strings, in
which case lua_tostring() returns NULL. Trigger undefined behavior.
This commit is contained in:
wm4 2014-10-24 21:56:45 +02:00
parent 55e3dab7eb
commit ef252b2314
1 changed files with 4 additions and 2 deletions

View File

@ -346,8 +346,10 @@ static int run_lua(lua_State *L)
// run this under an error handler that can do backtraces
lua_pushcfunction(L, error_handler); // errf
lua_pushcfunction(L, load_scripts); // errf fn
if (lua_pcall(L, 0, 0, -2)) // errf [error]
MP_FATAL(ctx, "Lua error: %s\n", lua_tostring(L, -1));
if (lua_pcall(L, 0, 0, -2)) { // errf [error]
const char *e = lua_tostring(L, -1);
MP_FATAL(ctx, "Lua error: %s\n", e ? e : "(unknown)");
}
return 0;
}