This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Patch for bug in libio (iostream.cc)
- To: egcs at cygnus dot com
- Subject: Patch for bug in libio (iostream.cc)
- From: Ard Kuijpers <ard at wfw dot wtb dot tue dot nl>
- Date: Thu, 11 Dec 1997 16:10:25 +0100
- Reply-To: egcs at cygnus dot com
Hello all,
Unfortunately, I got zero response on my two bug reports, but I
managed to find some spare time to dive into the libio internals and
fix it myself. In 'iostream.cc' the structure 'printf_info' was
incorrectly initialized. This structure was only incorrectly
initialized for glibc-2. The bug caused the fill character to be
initialized to '\0' instead of the value of '_fill' variable. The bug
is present in egcs-971201, egcs-1.0 and egcs-971207 (and possibly in
older versions as well).
The bug can be exposed with the following piece of code:
---begin code---
#include <iostream.h>
#include <iomanip.h>
int main()
{
cout << "'..1' == '" << setfill('.') << setw(3) << double(1) << "'\n";
return 0;
}
---end code-----
If this doesn't print
..1 == ..1
the bug is present in libstdc++.
Here is the patch to fix the bug:
---begin patch---
This is a patch for libstdc++-2.8.0 to fix a bug in the printf_info
initialization for ostream::operator<<(double) and
ostream::operator<<(long double) in comibination with glibc 2.
Ard
-----
Thu Dec 11 15:37:09 1997 Ard Kuijpers <ard@wfw.wtb.tue.nl>
* iostream.cc (ostream::operator<<([long] double):
rearranged initialization sequence for printf_info structure to
match the structure defined in /usr/include/printf.h for glibc 2.
diff -c3p egcs-1.0/libio/iostream.cc.orig egcs-1.0/libio/iostream.cc
*** egcs-1.0/libio/iostream.cc.orig Fri Oct 3 19:14:02 1997
--- egcs-1.0/libio/iostream.cc Thu Dec 11 14:33:09 1997
*************** ostream& ostream::operator<<(double n)
*** 628,637 ****
left: (flags() & ios::left) != 0,
showsign: (flags() & ios::showpos) != 0,
group: 0,
- pad: fill()
#if defined __GLIBC__ && __GLIBC__ >= 2
! , extra: 0
#endif
};
const void *ptr = (const void *) &n;
if (__printf_fp (rdbuf(), &info, &ptr) < 0)
--- 628,637 ----
left: (flags() & ios::left) != 0,
showsign: (flags() & ios::showpos) != 0,
group: 0,
#if defined __GLIBC__ && __GLIBC__ >= 2
! extra: 0,
#endif
+ pad: fill()
};
const void *ptr = (const void *) &n;
if (__printf_fp (rdbuf(), &info, &ptr) < 0)
*************** ostream& ostream::operator<<(long double
*** 731,740 ****
left: (flags() & ios::left) != 0,
showsign: (flags() & ios::showpos) != 0,
group: 0,
- pad: fill()
#if defined __GLIBC__ && __GLIBC__ >= 2
! , extra: 0
#endif
};
const void *ptr = (const void *) &n;
--- 731,740 ----
left: (flags() & ios::left) != 0,
showsign: (flags() & ios::showpos) != 0,
group: 0,
#if defined __GLIBC__ && __GLIBC__ >= 2
! extra: 0,
#endif
+ pad: fill()
};
const void *ptr = (const void *) &n;
---end patch-----
****************************************************************************
Ard Kuijpers
Faculty of Mechanical Engineering e-mail:ard@wfw.wtb.tue.nl
Eindhoven University of Technology phone: +31 40 2472811
P.O. Box 513, 5600 MB Eindhoven, The Netherlands fax: +31 40 2461418
****************************************************************************
"...Do what makes your heart hurt less..." _follow_your_heart_ THE PALADINS
****************************************************************************