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 e0cbaa50fa).
This commit is contained in:
Roberto Ierusalimschy
2020-03-16 14:13:13 -03:00
parent e460752323
commit 513559cc47
3 changed files with 19 additions and 8 deletions

View File

@@ -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;
}