From e0cbaa50fa7e97a8b7404041a59caac47b3949a5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 17 Dec 2019 10:49:55 -0300 Subject: [PATCH] Added test for NULL in string.format("%p") ISO C states that standard library functions should not be called with NULL arguments, unless stated otherwise. 'sprintf' does not state otherwise, and it doesn't hurt to be on the safe side. --- lstrlib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lstrlib.c b/lstrlib.c index 586e0d78..e47a1d8d 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1271,6 +1271,8 @@ static int str_format (lua_State *L) { } case 'p': { const void *p = lua_topointer(L, arg); + if (p == NULL) + p = "(null)"; /* NULL not a valid parameter in ISO C 'printf' */ nb = l_sprintf(buff, maxitem, form, p); break; }