Skip to content

Commit

Permalink
Added test for NULL in string.format("%p")
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
roberto-ieru committed Dec 17, 2019
1 parent 3747487 commit e0cbaa5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lstrlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,8 @@ 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' */
nb = l_sprintf(buff, maxitem, form, p);
break;
}
Expand Down

0 comments on commit e0cbaa5

Please sign in to comment.