summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-12-17 10:49:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-12-17 10:49:55 -0300
commite0cbaa50fa7e97a8b7404041a59caac47b3949a5 (patch)
treeaca8070ca14b0823b2bec895610f43d0013feffe
parent37474873203f247552021ab5856ab69d777166a2 (diff)
downloadlua-e0cbaa50fa7e97a8b7404041a59caac47b3949a5.tar.gz
lua-e0cbaa50fa7e97a8b7404041a59caac47b3949a5.tar.bz2
lua-e0cbaa50fa7e97a8b7404041a59caac47b3949a5.zip
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.
-rw-r--r--lstrlib.c2
1 files changed, 2 insertions, 0 deletions
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) {
1271 } 1271 }
1272 case 'p': { 1272 case 'p': {
1273 const void *p = lua_topointer(L, arg); 1273 const void *p = lua_topointer(L, arg);
1274 if (p == NULL)
1275 p = "(null)"; /* NULL not a valid parameter in ISO C 'printf' */
1274 nb = l_sprintf(buff, maxitem, form, p); 1276 nb = l_sprintf(buff, maxitem, form, p);
1275 break; 1277 break;
1276 } 1278 }