From 9a4b4cfc1a49c1537a852f6e40d2f3e0c4d3e0b2 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Sun, 21 Apr 2002 04:15:29 +0000 Subject: [PATCH] re PR libstdc++/6360 (Wrong workaround in char_traits.h - ignore stops on \0xff) 2002-04-20 Benjamin Kosnik PR libstdc++/6360 * include/bits/istream.tcc (istream::ignore): Streamline, use delimiter as is. * include/bits/streambuf.tcc: Use this->gptr. * testsuite/27_io/istream_unformatted.cc (test08): Add test. From-SVN: r52563 --- libstdc++-v3/ChangeLog | 8 ++++++ libstdc++-v3/include/bits/istream.tcc | 22 ++++++++-------- libstdc++-v3/include/bits/streambuf.tcc | 2 +- .../testsuite/27_io/istream_unformatted.cc | 25 ++++++++++++++++--- 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 42ac41617ef..6550006a583 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2002-04-20 Benjamin Kosnik + + PR libstdc++/6360 + * include/bits/istream.tcc (istream::ignore): Streamline, use + delimiter as is. + * include/bits/streambuf.tcc: Use this->gptr. + * testsuite/27_io/istream_unformatted.cc (test08): Add test. + 2002-04-18 Benjamin Kosnik * include/bits/localefwd.h (locale::id::_M_id): Do this correctly, diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 6b2e4ca4acb..a55e9063268 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -708,29 +708,27 @@ namespace std { _M_gcount = 0; sentry __cerb(*this, true); - if (__cerb && __n > 0) + if (__cerb) { try { - const int_type __idelim = traits_type::to_int_type(__delim); const int_type __eof = traits_type::eof(); __streambuf_type* __sb = this->rdbuf(); - int_type __c = __sb->sbumpc(); - bool __testdelim = __c == __idelim; - bool __testeof = __c == __eof; + int_type __c = __sb->sgetc(); __n = min(__n, numeric_limits::max()); - while (_M_gcount < __n - 1 && !__testeof && !__testdelim) + while (_M_gcount < __n && __c !=__eof && __c != __delim) { + __c = __sb->snextc(); ++_M_gcount; - __c = __sb->sbumpc(); - __testeof = __c == __eof; - __testdelim = __c == __idelim; } - if ((_M_gcount == __n - 1 && !__testeof) || __testdelim) - ++_M_gcount; - if (__testeof) + if (__c == __eof) this->setstate(ios_base::eofbit); + else if (__c == __delim) + { + __sb->snextc(); + ++_M_gcount; + } } catch(exception& __fail) { diff --git a/libstdc++-v3/include/bits/streambuf.tcc b/libstdc++-v3/include/bits/streambuf.tcc index 607800e19e0..292999cfba3 100644 --- a/libstdc++-v3/include/bits/streambuf.tcc +++ b/libstdc++-v3/include/bits/streambuf.tcc @@ -51,7 +51,7 @@ namespace std int_type __ret; if (_M_in_cur && _M_in_cur < _M_in_end) { - char_type __c = *gptr(); + char_type __c = *(this->gptr()); _M_in_cur_move(1); __ret = traits_type::to_int_type(__c); } diff --git a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc index 19c2c9242e6..bf25be8992a 100644 --- a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc +++ b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc @@ -1,6 +1,6 @@ // 1999-08-11 bkoz -// Copyright (C) 1999, 2000, 2001 Free Software Foundation +// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -463,7 +463,7 @@ test06() // bug reported by bgarcia@laurelnetworks.com // http://gcc.gnu.org/ml/libstdc++-prs/2000-q3/msg00041.html -int +void test07() { bool test = true; @@ -481,9 +481,25 @@ test07() line = line_ss.str(); VERIFY( line == "1234567890" || line == "" ); } - return 0; } - + +// 2002-04-19 PR libstdc++ 6360 +void +test08() +{ + using namespace std; + bool test = true; + + stringstream ss("abcd" "\xFF" "1234ina donna coolbrith"); + char c; + ss >> c; + VERIFY( c == 'a' ); + ss.ignore(8); + ss >> c; + VERIFY( c == 'i' ); +} + + int main() { @@ -494,6 +510,7 @@ main() test05(); test06(); test07(); + test08(); return 0; } -- 2.30.2