From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Pierre Carrier <pierre@spotify.com>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] lib/vsprintf.c: "%#o",0 becomes '0' instead of '00'
Date: Mon, 7 May 2012 10:19:49 +1000 [thread overview]
Message-ID: <20120507101949.e18a8f3e222b178eeb699cf6@canb.auug.org.au> (raw)
In-Reply-To: <1336228350-31148-1-git-send-email-pierre@spotify.com>
[-- Attachment #1: Type: text/plain, Size: 1336 bytes --]
Hi Pierre,
Thanks for doing this. Comments below.
On Sat, 5 May 2012 16:32:30 +0200 Pierre Carrier <pierre@spotify.com> wrote:
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index abbabec..7129383 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -284,6 +284,7 @@ char *number(char *buf, char *end, unsigned long long num,
> char locase;
> int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10);
> int i;
> + bool is_null = num == 0LL;
"num" is a number not a pointer, so I would call it "is_zero" (or just do
the comparisons explicitly below).
> /* locase = 0 or 0x20. ORing digits or letters with 'locase'
> * produces same digits or (maybe lowercased) letters */
> @@ -353,9 +354,11 @@ char *number(char *buf, char *end, unsigned long long num,
> }
> /* "0x" / "0" prefix */
> if (need_pfx) {
> - if (buf < end)
> - *buf = '0';
> - ++buf;
> + if (spec.base == 16 || !is_null) {
> + if (buf < end)
> + *buf = '0';
> + ++buf;
> + }
> if (spec.base == 16) {
> if (buf < end)
> *buf = ('X' | locase);
There is also another earlier section that tests "need_pfx" that reduces
the field width. You should fix that up as well.
--
Cheers,
Stephen Rothwell sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-05-07 0:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-05 14:32 [PATCH 1/1] lib/vsprintf.c: "%#o",0 becomes '0' instead of '00' Pierre Carrier
2012-05-07 0:19 ` Stephen Rothwell [this message]
2012-05-07 1:20 ` Pierre Carrier
2012-05-07 1:59 ` Joe Perches
2012-05-07 2:20 ` Pierre Carrier
2012-05-07 3:55 ` Stephen Rothwell
2012-05-07 3:56 ` Stephen Rothwell
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=20120507101949.e18a8f3e222b178eeb699cf6@canb.auug.org.au \
--to=sfr@canb.auug.org.au \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pierre@spotify.com \
/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;
as well as URLs for NNTP newsgroup(s).