Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LsaJQ-0001sl-1a for mharc-grub-devel@gnu.org; Sat, 11 Apr 2009 06:19:48 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LsaJO-0001rh-40 for grub-devel@gnu.org; Sat, 11 Apr 2009 06:19:46 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LsaJN-0001rK-JP for grub-devel@gnu.org; Sat, 11 Apr 2009 06:19:45 -0400 Received: from [199.232.76.173] (port=59314 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsaJN-0001rF-B9 for grub-devel@gnu.org; Sat, 11 Apr 2009 06:19:45 -0400 Received: from mail.nexedi.com ([91.121.25.85]:50182 helo=nexedi.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LsaJN-0001GK-1i for grub-devel@gnu.org; Sat, 11 Apr 2009 06:19:45 -0400 Received: from [10.8.0.46] (unknown [10.8.0.46]) by nexedi.com (Postfix) with ESMTP id 2D3A03D9FA for ; Sat, 11 Apr 2009 12:19:43 +0200 (CEST) From: "Yoshinori K. Okuji" Organization: enbug.org To: The development of GRUB 2 Date: Sat, 11 Apr 2009 19:19:49 +0900 User-Agent: KMail/1.9.10 References: <20090411.010829.45951849.davem@davemloft.net> In-Reply-To: <20090411.010829.45951849.davem@davemloft.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904111919.49761.okuji@enbug.org> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit. X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Apr 2009 10:19:46 -0000 On Saturday 11 April 2009 17:08:29 David Miller wrote: > The grub printf code tries to treat 'long' and 'int' the same, > that doesn't work on (most) 64-bit platforms. Right. Good finding. Regards, Okuji > > 2009-04-11 David S. Miller > > * kern/misc.c (grub_ltoa): New function. > (grub_vsprintf): Use it to format 'long' integers. > --- > kern/misc.c | 35 +++++++++++++++++++++++++++++++---- > 1 files changed, 31 insertions(+), 4 deletions(-) > > diff --git a/kern/misc.c b/kern/misc.c > index 23eaa14..85a5d95 100644 > --- a/kern/misc.c > +++ b/kern/misc.c > @@ -590,6 +590,31 @@ grub_itoa (char *str, int c, unsigned n) > return p; > } > > +static char * > +grub_ltoa (char *str, int c, unsigned long n) > +{ > + unsigned long base = (c == 'x') ? 16 : 10; > + char *p; > + > + if ((long) n < 0 && c == 'd') > + { > + n = (unsigned) (-((long) n)); > + *str++ = '-'; > + } > + > + p = str; > + do > + { > + unsigned long d = n % base; > + *p++ = (d > 9) ? d + 'a' - 10 : d + '0'; > + } > + while (n /= base); > + *p = 0; > + > + grub_reverse (str); > + return p; > +} > + > /* Divide N by D, return the quotient, and store the remainder in *R. */ > grub_uint64_t > grub_divmod64 (grub_uint64_t n, grub_uint32_t d, grub_uint32_t *r) > @@ -790,12 +815,14 @@ grub_vsprintf (char *str, const char *fmt, va_list > args) ll = va_arg (args, long long); > grub_lltoa (tmp, c, ll); > } > + else if (longfmt) > + { > + long l = va_arg (args, long); > + grub_ltoa (tmp, c, l); > + } > else > { > - if (longfmt) > - n = va_arg (args, long); > - else > - n = va_arg (args, int); > + n = va_arg (args, int); > grub_itoa (tmp, c, n); > } > if (! rightfill && grub_strlen (tmp) < format1)