aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPierre Carrier <pierre@spotify.com>2012-05-29 18:07:35 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-05-29 19:22:33 -0400
commit7c20342230ff370c397fc4a9c4c1e7a91964bb66 (patch)
treee9ccb5eaee5bcd4578f7ea30311f2c3830815b9c /lib
parent5536805292e64393f57054de66578f17eb1ea994 (diff)
lib/vsprintf.c: "%#o",0 becomes '0' instead of '00'
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> Acked-by: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index f5dfe0ca34f6..5391299c1e78 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -284,6 +284,7 @@ char *number(char *buf, char *end, unsigned long long num,
284 char locase; 284 char locase;
285 int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); 285 int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10);
286 int i; 286 int i;
287 bool is_zero = num == 0LL;
287 288
288 /* locase = 0 or 0x20. ORing digits or letters with 'locase' 289 /* locase = 0 or 0x20. ORing digits or letters with 'locase'
289 * produces same digits or (maybe lowercased) letters */ 290 * produces same digits or (maybe lowercased) letters */
@@ -305,8 +306,9 @@ char *number(char *buf, char *end, unsigned long long num,
305 } 306 }
306 } 307 }
307 if (need_pfx) { 308 if (need_pfx) {
308 spec.field_width--;
309 if (spec.base == 16) 309 if (spec.base == 16)
310 spec.field_width -= 2;
311 else if (!is_zero)
310 spec.field_width--; 312 spec.field_width--;
311 } 313 }
312 314
@@ -353,9 +355,11 @@ char *number(char *buf, char *end, unsigned long long num,
353 } 355 }
354 /* "0x" / "0" prefix */ 356 /* "0x" / "0" prefix */
355 if (need_pfx) { 357 if (need_pfx) {
356 if (buf < end) 358 if (spec.base == 16 || !is_zero) {
357 *buf = '0'; 359 if (buf < end)
358 ++buf; 360 *buf = '0';
361 ++buf;
362 }
359 if (spec.base == 16) { 363 if (spec.base == 16) {
360 if (buf < end) 364 if (buf < end)
361 *buf = ('X' | locase); 365 *buf = ('X' | locase);