public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Bernd Petrovitsch' <bernd@petrovitsch.priv.at>,
	'Joe Perches' <joe@perches.com>,
	LKML <linux-kernel@vger.kernel.org>
Cc: kernel-janitors <kernel-janitors@vger.kernel.org>
Subject: RE: Use of '%#02x' is almost always wrong
Date: Thu, 14 Oct 2021 08:27:17 +0000	[thread overview]
Message-ID: <5cf03008e8784b7797feaf3d8ccfa303@AcuMS.aculab.com> (raw)
In-Reply-To: <9bae5c76-db1e-b9e3-cdfa-ab22f9d8b58c@petrovitsch.priv.at>

From: Bernd Petrovitsch
> Sent: 14 October 2021 00:16
> 
> On 12/10/2021 23:10, David Laight wrote:
> [...]
> >> So presumably all the uses of %#02x in the kernel are not outputting
> >> what is actually expected.  Perhaps all of these should use %#04x.
> >
> > Doesn't help. The definition of "%#x" is completely broken.
> 
> Seconded ...
> 
> > Basically 0 doesn't get the "0x" prefix, so "%#04x" outputs
> > "0000".
> 
> ... just because of that.
> And if one get's in touch with tools where format strings are
> the % -stuff is not consistently used ...
> 
> > "0000" if the value is zero.
> > So the correct replacement is (probably) "0x%02x".
> 
> At least it's consistent that way.
> 
> And in the big techie picture, I don't see what the '#' modifer
> buys and why it makes sense to use it.

It works for "%#8x" where it add the "0x" to the right-aligned
hex digits.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2021-10-14  8:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-10 16:45 Use of '%#02x' is almost always wrong Joe Perches
2021-10-12 21:10 ` David Laight
2021-10-13 23:16   ` Bernd Petrovitsch
2021-10-14  8:27     ` David Laight [this message]
2021-10-13  6:15 ` Dan Carpenter
2021-10-13  8:17   ` Joe Perches
2021-10-13 10:39     ` Dan Carpenter

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=5cf03008e8784b7797feaf3d8ccfa303@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=bernd@petrovitsch.priv.at \
    --cc=joe@perches.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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