Tricky _PROMPT may trigger undefined behavior in lua.c

This commit is contained in:
Roberto Ierusalimschy 2024-06-12 16:04:25 -03:00
parent b529aefc53
commit aaf3533653

5
lua.c
View File

@ -115,12 +115,13 @@ static void l_message (const char *pname, const char *msg) {
/*
** Check whether 'status' is not OK and, if so, prints the error
** message on the top of the stack. It assumes that the error object
** is a string, as it was either generated by Lua or by 'msghandler'.
** message on the top of the stack.
*/
static int report (lua_State *L, int status) {
if (status != LUA_OK) {
const char *msg = lua_tostring(L, -1);
if (msg == NULL)
msg = "(error message not a string)";
l_message(progname, msg);
lua_pop(L, 1); /* remove message */
}