This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Very serious bug...
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Subject: Very serious bug...
- From: Theodore Papadopoulo <Theodore dot Papadopoulo at sophia dot inria dot fr>
- Date: Mon, 05 Mar 2001 18:42:15 +0100
- Cc: bkoz at redhat dot com, gdr at codesourcery dot com
Hi,
libstdc++-v3 (mainline, I do not know about the branch) is badly
broken. The simple program:
#include <iostream>
int
main()
{
char buffer[256];
std::cin >> buffer; // Why does nothing is read here !!!! (TO).
std::cout << "Read: " << buffer << std::endl;
}
reads nothing:
vanuatu->g++ -v
Reading specs from /net/home/robotvis/gnu/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs
Configured with: ../../Cvs/gcc/configure --with-gnu-as --with-gnu-ld --with-as=/net/home/robotvis/gnu/binutils/bin/as --with-ld=/net/home/robotvis/gnu/binutils/bin/ld --prefix=/net/home/robotvis/gnu/gcc
gcc version 3.1 20010228 (experimental)
vanuatu->g++ -g Test1.C
vanuatu->./a.out
fjkhvfdjhfdjkd
Read:
It looks like this is related to an int/unsigned problem as in:
2001-03-02 Peter Schmid <schmid@snake.iap.physik.tu-darmstadt.de>
* include/bits/istream.tcc: change type of __extracted to __size_type
As pointed by Benjamin, the change
2001-02-11 Gabriel Dos Reis <gdr@codesourcery.com>
* include/bits/char_traits.h char_traits<char>::int_type: Change
to `int' to match 21.1.3.1/2.
* testsuite/21_strings/char_traits-int_type.C: New test.
seems to have non trivial repercussions.
Here the problem is that the following code (from
template<typename _CharT, typename _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s):
in istream.tcc):
int_type __num = static_cast<int_type>(__in.width());
if (__num <= 0)
__num = basic_string<_CharT, _Traits>::npos;
assume that __num is unsigned.
The following patch corrects the problem mentionned above, but it
looks like the implications of Gaby's patch need to be looked at
closely.
Theo.
Index: istream.tcc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.9
diff -c -3 -p -r1.9 istream.tcc
*** istream.tcc 2001/03/04 21:34:00 1.9
--- istream.tcc 2001/03/05 17:38:23
*************** namespace std {
*** 1016,1029 ****
typedef typename _Traits::int_type int_type;
typedef _CharT char_type;
typedef ctype<_CharT> __ctype_type;
! int_type __extracted = 0;
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
try {
// Figure out how many characters to extract.
! int_type __num = static_cast<int_type>(__in.width());
if (__num <= 0)
__num = basic_string<_CharT, _Traits>::npos;
--- 1016,1030 ----
typedef typename _Traits::int_type int_type;
typedef _CharT char_type;
typedef ctype<_CharT> __ctype_type;
! typedef size_t __size_type;
! __size_type __extracted = 0;
typename __istream_type::sentry __cerb(__in, false);
if (__cerb)
{
try {
// Figure out how many characters to extract.
! __size_type __num = _in.width();
if (__num <= 0)
__num = basic_string<_CharT, _Traits>::npos;
--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
--------------------------------------------------------------------
PGP signature