[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit.
From: |
Yoshinori K. Okuji |
Subject: |
Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit. |
Date: |
Sat, 11 Apr 2009 19:19:49 +0900 |
User-agent: |
KMail/1.9.10 |
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 <address@hidden>
>
> * 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)
- [PATCH]: grub: Fix handling of long printf arguments on 64-bit., David Miller, 2009/04/11
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit.,
Yoshinori K. Okuji <=
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., David Miller, 2009/04/11
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., phcoder, 2009/04/11
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., Pavel Roskin, 2009/04/11
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., David Miller, 2009/04/12
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., phcoder, 2009/04/12
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., Isaac Dupree, 2009/04/12
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., Pavel Roskin, 2009/04/12
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., Pavel Roskin, 2009/04/12
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., Pavel Roskin, 2009/04/12
- Re: [PATCH]: grub: Fix handling of long printf arguments on 64-bit., phcoder, 2009/04/12