aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-24 16:08:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-11-24 16:08:55 -0300
commit842a83f09caa2ebd4bc03e0076420148ac07c808 (patch)
tree92eca69ee75b32156b14c1a9d0b5a31f16ef9118 /ltests.c
parent7923dbbf72da303ca1cca17efd24725668992f15 (diff)
downloadlua-842a83f09caa2ebd4bc03e0076420148ac07c808.tar.gz
lua-842a83f09caa2ebd4bc03e0076420148ac07c808.tar.bz2
lua-842a83f09caa2ebd4bc03e0076420148ac07c808.zip
Panic functions should not raise errors
The standard panic function was using 'lua_tostring', which may raise a memory-allocation error if error value is a number.
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/ltests.c b/ltests.c
index 7d184c0d..c2943a4f 100644
--- a/ltests.c
+++ b/ltests.c
@@ -73,8 +73,9 @@ static void badexit (const char *fmt, const char *s1, const char *s2) {
73 73
74 74
75static int tpanic (lua_State *L) { 75static int tpanic (lua_State *L) {
76 const char *msg = lua_tostring(L, -1); 76 const char *msg = (lua_type(L, -1) == LUA_TSTRING)
77 if (msg == NULL) msg = "error object is not a string"; 77 ? lua_tostring(L, -1)
78 : "error object is not a string";
78 return (badexit("PANIC: unprotected error in call to Lua API (%s)\n", 79 return (badexit("PANIC: unprotected error in call to Lua API (%s)\n",
79 msg, NULL), 80 msg, NULL),
80 0); /* do not return to Lua */ 81 0); /* do not return to Lua */