From: George Spelvin Date: Wed, 26 Sep 2012 01:34:17 +0000 (+1000) Subject: lib-vsprintf-optimize-put_dec_trunc8-fix X-Git-Tag: next-20120927~1^2~152 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=613f59f0fd3128cd1e3ac0baa8c90198896815ca;p=karo-tx-linux.git lib-vsprintf-optimize-put_dec_trunc8-fix Rabin Vincent wrote: > This patch breaks IP address printing with "%pI4" (and by extension, > nfsroot). Example: > > - Before: 10.0.0.1 > - After: 10...1 Mea culpa, and thank you for catching it! As I said in my earlier comment, I tested this most extensively wrapped by some sprintf code that liked 0 converted to a 0-length string, as that works naturally with the ANSI spec for %.0u. And it turns out not to matter for the usual printf code, as num_to_str special-cases that anyway. The fix is straightforward: Signed-off-by: George Spelvin Cc: Rabin Vincent Cc: Denys Vlasenko Cc: Michal Nazarewicz Signed-off-by: Andrew Morton --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index f58fc4b1eaf0..c2236f14640f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -180,8 +180,6 @@ char *put_dec_trunc8(char *buf, unsigned r) *buf++ = q - 10*r; } - if (r == 0) - return buf; q = (r * 0x199a) >> 16; *buf++ = (r - 10 * q) + '0'; /* 6 */ if (q == 0)