[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug with built-in printf
From: |
Eric Blake |
Subject: |
Re: bug with built-in printf |
Date: |
Wed, 6 Dec 2006 16:06:12 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Chet Ramey <chet.ramey <at> case.edu> writes:
> > Using printf with a large integer results in incorrect conversion to
> > hexadecimal.
> >
> > Repeat-By:
> >
> > printf "%08X" 2604292517
> >
> > On this version results in the incorrect string "-64C5A65B".
>
> Thanks. I fixed it.
In the interest of open source, this is how I reproduced a fix for cygwin:
--- bash-3.2-orig/lib/sh/snprintf.c 2006-12-06 07:17:51.724375000 -0700
+++ bash-3.2/lib/sh/snprintf.c 2006-12-06 07:09:03.000000000 -0700
@@ -7,7 +7,7 @@
Unix snprintf implementation.
derived from inetutils/libinetutils/snprintf.c Version 1.1
- Copyright (C) 2001 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2006 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General License as published by
@@ -668,7 +668,8 @@
p->flags &= ~PF_ZEROPAD;
sd = d; /* signed for ' ' padding in base 10 */
- flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0;
+ flags = (*p->pf == 'u' || *p->pf == 'U' || *p->pf == 'x' || *p->pf == 'X'
+ || *p->pf == 'o') ? FL_UNSIGNED : 0;
if (*p->pf == 'X')
flags |= FL_HEXUPPER;
@@ -738,7 +739,8 @@
p->flags &= ~PF_ZEROPAD;
sd = d; /* signed for ' ' padding in base 10 */
- flags = (*p->pf == 'u' || *p->pf == 'U') ? FL_UNSIGNED : 0;
+ flags = (*p->pf == 'u' || *p->pf == 'U' || *p->pf == 'x' || *p->pf == 'X'
+ || *p->pf == 'o') ? FL_UNSIGNED : 0;
if (*p->pf == 'X')
flags |= FL_HEXUPPER;
--
Eric Blake