From d766e4b4b1cee6903c4c14312317b09481fa00aa Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Thu, 3 May 2012 15:44:18 +1000 Subject: [PATCH] vsprintf: correctly handle width when '#' flag used in %#p format. needs decent changelog! Signed-off-by: Grant Likely Signed-off-by: Andrew Morton --- lib/vsprintf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index abbabec9720a..1043827c3583 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -866,13 +866,15 @@ static noinline_for_stack char *pointer(const char *fmt, char *buf, char *end, void *ptr, struct printf_spec spec) { + int default_width = 2 * sizeof(void*) + (spec.flags & SPECIAL ? 2 : 0); + if (!ptr && *fmt != 'K') { /* * Print (null) with the same width as a pointer so it makes * tabular output look nice. */ if (spec.field_width == -1) - spec.field_width = 2 * sizeof(void *); + spec.field_width = default_width; return string(buf, end, "(null)", spec); } @@ -927,7 +929,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, */ if (in_irq() || in_serving_softirq() || in_nmi()) { if (spec.field_width == -1) - spec.field_width = 2 * sizeof(void *); + spec.field_width = default_width; return string(buf, end, "pK-error", spec); } if (!((kptr_restrict == 0) || @@ -944,7 +946,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, } spec.flags |= SMALL; if (spec.field_width == -1) { - spec.field_width = 2 * sizeof(void *); + spec.field_width = default_width; spec.flags |= ZEROPAD; } spec.base = 16; -- 2.39.5