From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758923AbZEFIeA (ORCPT ); Wed, 6 May 2009 04:34:00 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752478AbZEFIdv (ORCPT ); Wed, 6 May 2009 04:33:51 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:52805 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750938AbZEFIdu (ORCPT ); Wed, 6 May 2009 04:33:50 -0400 Message-ID: <4A014BA9.9020201@cn.fujitsu.com> Date: Wed, 06 May 2009 16:34:49 +0800 From: Li Zefan User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: Vegard Nossum CC: Lai Jiangshan , Ingo Molnar , Yinghai Lu , Frederic Weisbecker , Jeremy Fitzhardinge , Zhaolei , Steven Rostedt , Andrew Morton , "linux-kernel@vger.kernel.org" Subject: Re: printk %0*X is broken. References: <20090506081221.GA15317@damson.getinternet.no> <4A0149FD.3010008@cn.fujitsu.com> In-Reply-To: <4A0149FD.3010008@cn.fujitsu.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Lai Jiangshan wrote: > Vegard Nossum wrote: >> 2009/5/6 Ingo Molnar : >>> Cc:-ed more folks who modified lib/vsprintf.c recently. >>> >>> Ingo >>> >>> * Yinghai Lu 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. >> No, we break out of the while loop when we can't find a flag, So we are at '*' after we found '0'. >> 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; >> } >> > > It seems that your patch does not change anything. > The code logic is still the same as before. > > Lai > > >