From 513559cc4760392b6fa33754c516683ef49dba22 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 16 Mar 2020 14:13:13 -0300 Subject: 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). --- lstrlib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lstrlib.c') 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) { } case 'p': { const void *p = lua_topointer(L, arg); - if (p == NULL) - p = "(null)"; /* NULL not a valid parameter in ISO C 'printf' */ + if (p == NULL) { /* avoid calling 'printf' with argument NULL */ + p = "(null)"; /* result */ + form[strlen(form) - 1] = 's'; /* format it as a string */ + } nb = l_sprintf(buff, maxitem, form, p); break; } -- cgit v1.2.3-55-g6feb