public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] cmd_fdt.c: Use %p when printing pointers
Date: Tue, 30 Oct 2012 10:59:27 +0100	[thread overview]
Message-ID: <20121030095927.437502001B0@gemini.denx.de> (raw)
In-Reply-To: <1351558398-6902-1-git-send-email-trini@ti.com>

Dear Tom Rini,

In message <1351558398-6902-1-git-send-email-trini@ti.com> you wrote:
> When putting pointers into a format string use %p to ensure that they
> are printed correctly regardless of bitsize.  This fixes warnings on
> sandbox on 64bit systems.
> 
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Gerald Van Baren <vanbaren@cideas.com>
> Signed-off-by: Tom Rini <trini@ti.com>
> ---
>  common/cmd_fdt.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c
> index a5e2cfc..f9acfc1 100644
> --- a/common/cmd_fdt.c
> +++ b/common/cmd_fdt.c
> @@ -375,7 +375,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
>  					/* Get address */
>  					char buf[11];
>  
> -					sprintf(buf, "0x%08X", (uint32_t)nodep);
> +					sprintf(buf, "0x%p", nodep);
>  					setenv(var, buf);

This may put bogus data ("var=0x(null)") into the environment.

I see two approaches to fix this:

1) Handle this locally, say like that:

	char buf[11] = { '0', 0, };

	if (nodep)
		sprintf(buf, "0x%p", nodep);
	
	setenv(var, buf);

   This is the solution with minimal global impact.

2) Fix the root cause: given that we have valid situations where we
   may want to dereference a pointer pointing to address 0x0000, 
   I wonder if it would not actually be better (i. e. more correct) to
   get rid of the

   	495 static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
	496                 int field_width, int precision, int flags)
	497 {
	498         if (!ptr)
	499                 return string(buf, end, "(null)", field_width, precision,
	500                               flags);

   special handling in "lib/vsprintf.c"

   Would anybody shed any tears if we drop this?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
You could end up being oddly sad and full of a strange, diffuse  com-
passion  which would lead you to believe that it might be a good idea
to wipe out the whole human race and start again with amoebas.
                                 - Terry Pratchett, _Guards! Guards!_

  parent reply	other threads:[~2012-10-30  9:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-30  0:53 [U-Boot] [PATCH] cmd_fdt.c: Use %p when printing pointers Tom Rini
2012-10-30  1:36 ` Joe Hershberger
2012-10-30  9:59 ` Wolfgang Denk [this message]
2012-10-30 17:48   ` Joe Hershberger
2012-10-30 19:04     ` Wolfgang Denk
     [not found]   ` <508FCBBA.1070200@cideas.com>
2012-10-30 18:10     ` Tom Rini
2012-10-30 19:19   ` [U-Boot] [PATCH] lib/vsprintf.c: don't special-case pointers to address null Wolfgang Denk
2012-10-30 19:23     ` Joe Hershberger
2012-11-04 18:28       ` Tom Rini
2012-11-04 18:28 ` [U-Boot] [PATCH] cmd_fdt.c: Use %p when printing pointers Tom Rini

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=20121030095927.437502001B0@gemini.denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /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