aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-03-16 14:13:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-03-16 14:13:13 -0300
commit513559cc4760392b6fa33754c516683ef49dba22 (patch)
tree7080bdf0e31f0ce14545a0e8a68daff3b36cec62 /lstrlib.c
parente4607523234f16ed9ed0436340b9315377dbfe7f (diff)
downloadlua-513559cc4760392b6fa33754c516683ef49dba22.tar.gz
lua-513559cc4760392b6fa33754c516683ef49dba22.tar.bz2
lua-513559cc4760392b6fa33754c516683ef49dba22.zip
Fixed bug in 'string.format("%p")'
The string "(null)" used for non-collectable values must be printed as a string, not as a pointer. (Bug introduced in commit e0cbaa50fa7).
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 28df2d45..2ba8bde4 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1271,8 +1271,10 @@ 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) 1274 if (p == NULL) { /* avoid calling 'printf' with argument NULL */
1275 p = "(null)"; /* NULL not a valid parameter in ISO C 'printf' */ 1275 p = "(null)"; /* result */
1276 form[strlen(form) - 1] = 's'; /* format it as a string */
1277 }
1276 nb = l_sprintf(buff, maxitem, form, p); 1278 nb = l_sprintf(buff, maxitem, form, p);
1277 break; 1279 break;
1278 } 1280 }