linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] lib/vsprintf.c: "%#o",0 becomes '0' instead of '00'
@ 2012-05-05 14:32 Pierre Carrier
  2012-05-07  0:19 ` Stephen Rothwell
  0 siblings, 1 reply; 7+ messages in thread
From: Pierre Carrier @ 2012-05-05 14:32 UTC (permalink / raw)
  To: Stephen Rothwell, Andrew Morton; +Cc: linux-kernel, Pierre Carrier

number()'s behaviour is slighly changed:
0 becomes "0" instead of "00" when using the flag SPECIAL and base 8.

Before:
Number\Format  %o    %#o  %x    %#x
            0     0   00    0   0x0
            1     1   01    1   0x1
           16    20  020   10  0x10

After:
Number\Format  %o    %#o  %x    %#x
            0     0    0    0   0x0
            1     1   01    1   0x1
           16    20  020   10  0x10

Signed-off-by: Pierre Carrier <pierre@spotify.com>
---
 lib/vsprintf.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

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;
 
 	/* 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);
-- 
1.7.10.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-05-07  3:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).