aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-06-09 16:12:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-06-09 16:12:01 -0300
commit364e569945c044fd18c70ee1bc851364534aef97 (patch)
treead461207558d0452455a8180cf5d8b1e6e37d0be /ltests.c
parent63295f1f7fa052fabcb4d69d49203cf33a7deef0 (diff)
downloadlua-364e569945c044fd18c70ee1bc851364534aef97.tar.gz
lua-364e569945c044fd18c70ee1bc851364534aef97.tar.bz2
lua-364e569945c044fd18c70ee1bc851364534aef97.zip
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.)
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/ltests.c b/ltests.c
index 7e6d8610..314505c3 100644
--- a/ltests.c
+++ b/ltests.c
@@ -73,8 +73,10 @@ 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);
77 if (msg == NULL) msg = "error object is not a string";
76 return (badexit("PANIC: unprotected error in call to Lua API (%s)\n", 78 return (badexit("PANIC: unprotected error in call to Lua API (%s)\n",
77 lua_tostring(L, -1), NULL), 79 msg, NULL),
78 0); /* do not return to Lua */ 80 0); /* do not return to Lua */
79} 81}
80 82