diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-17 10:49:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-12-17 10:49:55 -0300 |
commit | e0cbaa50fa7e97a8b7404041a59caac47b3949a5 (patch) | |
tree | aca8070ca14b0823b2bec895610f43d0013feffe /lstrlib.c | |
parent | 37474873203f247552021ab5856ab69d777166a2 (diff) | |
download | lua-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.
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -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 | } |