Skip to content

Commit

Permalink
Make %p print '(null)' for NULL pointers
Browse files Browse the repository at this point in the history
Before, when we only ever printed out the pointer value itself, a NULL
pointer would never cause issues and might as well be printed out as
just its numeric value.

However, with the extended %p formats, especially %pR, we might validly
want to print out resources for debugging.  And sometimes they don't
even exist, and the resource pointer is just NULL.  Print it out as
such, rather than oopsing.

This is a more generic version of a patch done by Trent Piepho (catching
all %p cases rather than just %pR, and using "(null)" instead of
"[NULL]" to match glibc).

Requested-by: Trent Piepho <[email protected]>
Acked-by: Harvey Harrison <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
torvalds committed Jan 3, 2009
1 parent 3bfacef commit d97106a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ static char *ip4_addr_string(char *buf, char *end, u8 *addr, int field_width,
*/
static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field_width, int precision, int flags)
{
if (!ptr)
return string(buf, end, "(null)", field_width, precision, flags);

switch (*fmt) {
case 'F':
ptr = dereference_function_descriptor(ptr);
Expand Down

0 comments on commit d97106a

Please sign in to comment.