Skip to content

Commit 34d8726

Browse files
committedMay 15, 2014
Make print() NUL-safe
1 parent c8a9940 commit 34d8726

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed
 

‎src/script/lua_api/l_util.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ int ModApiUtil::l_debug(lua_State *L)
4747
lua_pushvalue(L, -1); /* function to be called */
4848
lua_pushvalue(L, i); /* value to print */
4949
lua_call(L, 1, 1);
50-
const char *s = lua_tostring(L, -1);
51-
if (i>1)
50+
size_t len;
51+
const char *s = lua_tolstring(L, -1, &len);
52+
if (i > 1)
5253
dstream << "\t";
5354
if (s)
54-
dstream << s;
55+
dstream << std::string(s, len);
5556
lua_pop(L, 1);
5657
}
5758
dstream << std::endl;

0 commit comments

Comments
 (0)