From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Lt7an-00038P-UU for mharc-grub-devel@gnu.org; Sun, 12 Apr 2009 17:51:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lt7al-00037n-RW for grub-devel@gnu.org; Sun, 12 Apr 2009 17:51:55 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lt7ah-00037T-EK for grub-devel@gnu.org; Sun, 12 Apr 2009 17:51:55 -0400 Received: from [199.232.76.173] (port=51403 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lt7ah-00037Q-8T for grub-devel@gnu.org; Sun, 12 Apr 2009 17:51:51 -0400 Received: from c60.cesmail.net ([216.154.195.49]:37800) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1Lt7ag-0003xK-PS for grub-devel@gnu.org; Sun, 12 Apr 2009 17:51:51 -0400 Received: from unknown (HELO smtprelay2.cesmail.net) ([192.168.1.112]) by c60.cesmail.net with ESMTP; 12 Apr 2009 17:51:49 -0400 Received: from [192.168.0.220] (pool-141-151-93-148.phlapa.east.verizon.net [141.151.93.148]) by smtprelay2.cesmail.net (Postfix) with ESMTPSA id 43A8534C6A for ; Sun, 12 Apr 2009 17:53:18 -0400 (EDT) From: Pavel Roskin To: The development of GRUB 2 In-Reply-To: <1239572015.14481.32.camel@ct> References: <200904111919.49761.okuji@enbug.org> <20090411.044848.183598331.davem@davemloft.net> <49E0EB22.4070308@gmail.com> <20090412.010719.229891360.davem@davemloft.net> <49E1E2BC.3020405@gmail.com> <1239572015.14481.32.camel@ct> Content-Type: text/plain Date: Sun, 12 Apr 2009 17:51:47 -0400 Message-Id: <1239573107.14481.41.camel@ct> Mime-Version: 1.0 X-Mailer: Evolution 2.24.5 (2.24.5-1.fc10) Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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: Sun, 12 Apr 2009 21:51:56 -0000 On Sun, 2009-04-12 at 17:33 -0400, Pavel Roskin wrote: > If the type is going to be converted, we need to treat signed and > unsigned values separately. This is compile tested only, to show what I mean. The size of kernel.img is reduced from 31220 to 31124. The code looks long, but I'm sure an optimizing compiler can simplify it well. Variable names are changed for readability. Index: kern/misc.c =================================================================== --- kern/misc.c (revision 2087) +++ kern/misc.c (working copy) @@ -565,56 +565,6 @@ } } -static char * -grub_itoa (char *str, int c, unsigned n) -{ - unsigned base = (c == 'x') ? 16 : 10; - char *p; - - if ((int) n < 0 && c == 'd') - { - n = (unsigned) (-((int) n)); - *str++ = '-'; - } - - p = str; - do - { - unsigned d = n % base; - *p++ = (d > 9) ? d + 'a' - 10 : d + '0'; - } - while (n /= base); - *p = 0; - - grub_reverse (str); - 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) (-((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) @@ -807,23 +757,36 @@ /* fall through */ case 'x': case 'u': + if (longlongfmt) + { + unsigned long long ull = va_arg (args, unsigned long long); + grub_lltoa (tmp, c, ull); + } + else if (longfmt) + { + unsigned long ul = va_arg (args, unsigned long); + grub_lltoa (tmp, c, ul); + } + else + { + unsigned int ui = va_arg (args, unsigned int); + grub_lltoa (tmp, c, ui); + } case 'd': if (longlongfmt) { - long long ll; - - ll = va_arg (args, long long); - grub_lltoa (tmp, c, ll); + long long sll = va_arg (args, long long); + grub_lltoa (tmp, c, sll); } else if (longfmt) { - long l = va_arg (args, long); - grub_ltoa (tmp, c, l); + long sl = va_arg (args, long); + grub_lltoa (tmp, c, sl); } else { - n = va_arg (args, int); - grub_itoa (tmp, c, n); + int si = va_arg (args, int); + grub_lltoa (tmp, c, si); } if (! rightfill && grub_strlen (tmp) < format1) write_fill (zerofill, format1 - grub_strlen (tmp)); -- Regards, Pavel Roskin