Pārlūkot izejas kodu

Bug: Tricky _PROMPT may trigger undefined behavior

Roberto Ierusalimschy 1 gadu atpakaļ
vecāks
revīzija
21ff8de33a
1 mainītis faili ar 3 papildinājumiem un 2 dzēšanām
  1. 3 2
      lua.c

+ 3 - 2
lua.c

@@ -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 */
   }