summaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
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) {
}
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;
}