mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Trent Piepho <xyzzy@speakeasy.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Harvey Harrison <harvey.harrison@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] printk: Let %pR handle NULL pointers
Date: Sat, 3 Jan 2009 09:10:40 -0800 (PST)	[thread overview]
Message-ID: <alpine.LFD.2.00.0901030905140.3179@localhost.localdomain> (raw)
In-Reply-To: <1230979341-23029-1-git-send-email-xyzzy@speakeasy.org>



On Sat, 3 Jan 2009, Trent Piepho wrote:
>
> Have %pR print "[NULL]" for the resource range when passed a NULL pointer.

Wouldn't it be much nicer to just do it for _all_ pointer types?

IOW, a patch more like the appended.

Also, I'm not 100% sure that "[NULL]" is the right thing to print. Not 
that I know if there's anything better. Testing glibc, it prints "(nil)" 
for a NULL string (%s) and "(null)" for a NULL pointer (%p). Which makes 
no more sense than anything else, but maybe we could make the NULL %p case 
at least match that if for no other reason than the fact that it would 
match _something_.

Added the other people who added %pX modifiers to the cc - I guess the 
networking people probably never have NULL pointers there anyway, but 
maybe they have opinions.

		Linus

---
 lib/vsprintf.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3b77702..4df1884 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -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);

  reply	other threads:[~2009-01-03 17:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-03 10:42 Trent Piepho
2009-01-03 17:10 ` Linus Torvalds [this message]
2009-01-03 19:33   ` Harvey Harrison
2009-01-03 21:53   ` Benjamin Herrenschmidt
2009-01-04  5:02     ` Trent Piepho
2009-01-04  5:14       ` Valdis.Kletnieks
2009-01-04  9:31         ` Johannes Berg
2009-01-04  9:48       ` Benjamin Herrenschmidt
2009-01-04 20:41         ` Trent Piepho

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.00.0901030905140.3179@localhost.localdomain \
    --to=torvalds@linux-foundation.org \
    --cc=benh@kernel.crashing.org \
    --cc=davem@davemloft.net \
    --cc=harvey.harrison@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xyzzy@speakeasy.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome