Avoid calling 'fprintf' with NULL

Avoid undefined behavior in calls like «fprintf("%s", NULL)».
('lua_writestringerror' is implemented as 'fprintf', and 'lua_tostring'
can return NULL if object is not a string.)
This commit is contained in:
Roberto Ierusalimschy
2020-06-09 16:12:01 -03:00
parent 63295f1f7f
commit 364e569945
3 changed files with 7 additions and 3 deletions

View File

@@ -417,7 +417,7 @@ static int db_debug (lua_State *L) {
return 0;
if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
lua_pcall(L, 0, 0, 0))
lua_writestringerror("%s\n", lua_tostring(L, -1));
lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL));
lua_settop(L, 0); /* remove eventual returns */
}
}