lkml.org 
[lkml]   [2009]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: printk %0*X is broken.
2009/5/6 Ingo Molnar <mingo@elte.hu>:
>
> Cc:-ed more folks who modified lib/vsprintf.c recently.
>
> Ingo
>
> * Yinghai Lu <yinghai@kernel.org> wrote:
>
>> it seems someone broke
>>
>> printk( "%0*X\n", width, x);
>>
>> looks like 0 is dumped.

After %, we look for flags. The problem is that when a flag is found, we
don't advance in the format string. And thus we start looking for the
precision, which is read as 0, because we are still at the 0. I think
this patch should fix it.

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7536ace..ae7d4b2 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -800,14 +800,15 @@ static int format_decode(const char *fmt, struct printf_spec *spec)
if (fmt != start || !*fmt)
return fmt - start;

+ /* this skips the first '%' */
+ ++fmt;
+
/* Process flags */
spec->flags = 0;

- while (1) { /* this also skips first '%' */
+ while (1) {
bool found = true;

- ++fmt;
-
switch (*fmt) {
case '-': spec->flags |= LEFT; break;
case '+': spec->flags |= PLUS; break;
@@ -819,6 +820,8 @@ static int format_decode(const char *fmt, struct printf_spec *spec)

if (!found)
break;
+
+ ++fmt;
}

/* get field width */

\
 
 \ /
  Last update: 2009-05-06 10:17    [W:0.075 / U:18.712 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site