From: Benjamin Kosnik Date: Wed, 6 Nov 2002 00:08:37 +0000 (+0000) Subject: re PR libstdc++/8258 (basic_istream::readsome() with default buffer change stream... X-Git-Tag: releases/gcc-3.2.1~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7aa53f7b2e0ab380ba8a945301fbc4f02d29e7fa;p=thirdparty%2Fgcc.git re PR libstdc++/8258 (basic_istream::readsome() with default buffer change stream state to ios_base::eofbit) 2002-11-05 Benjamin Kosnik PR libstdc++/8258 * include/bits/istream.tcc (istream::readsome): Don't set eofbit for null buffer. (istream::operator>>(_CharT*)): Use traits_type. (istream::ws): Same. (istream::operator>>(string)): Same. * testsuite/27_io/istream_unformatted.cc (test11): Add. From-SVN: r58845 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 31a2e636d5a5..c25f6e37d4a4 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2002-11-05 Benjamin Kosnik + + PR libstdc++/8258 + * include/bits/istream.tcc (istream::readsome): Don't set eofbit + for null buffer. + (istream::operator>>(_CharT*)): Use traits_type. + (istream::ws): Same. + (istream::operator>>(string)): Same. + * testsuite/27_io/istream_unformatted.cc (test11): Add. + 2002-11-05 Benjamin Kosnik PR libstdc++/7219 diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 617110d953b8..a6e49a923bd2 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -811,8 +811,9 @@ namespace std { try { + // Cannot compare int_type with streamsize generically. streamsize __num = this->rdbuf()->in_avail(); - if (__num > 0) + if (__num >= 0) { __num = min(__num, __n); if (__num) @@ -1034,13 +1035,14 @@ namespace std int_type __c = __sb->sgetc(); while (__extracted < __num - 1 - && __c != __eof && !__ctype.is(ctype_base::space, __c)) + && !_Traits::eq_int_type(__c, __eof) + && !__ctype.is(ctype_base::space, __c)) { *__s++ = __c; ++__extracted; __c = __sb->snextc(); } - if (__c == __eof) + if (_Traits::eq_int_type(__c, __eof)) __in.setstate(ios_base::eofbit); #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS @@ -1078,9 +1080,11 @@ namespace std __streambuf_type* __sb = __in.rdbuf(); __int_type __c = __sb->sgetc(); - while (__c != __eof && __ctype.is(ctype_base::space, __c)) + while (!_Traits::eq_int_type(__c, __eof) + && __ctype.is(ctype_base::space, __c)) __c = __sb->snextc(); - if (__c == __eof) + + if (_Traits::eq_int_type(__c, __eof)) __in.setstate(ios_base::eofbit); return __in; @@ -1114,13 +1118,14 @@ namespace std __int_type __c = __sb->sgetc(); while (__extracted < __n - && __c != __eof && !__ctype.is(ctype_base::space, __c)) + && !_Traits::eq_int_type(__c, __eof) + && !__ctype.is(ctype_base::space, __c)) { __str += _Traits::to_char_type(__c); ++__extracted; __c = __sb->snextc(); } - if (__c == __eof) + if (_Traits::eq_int_type(__c, __eof)) __in.setstate(ios_base::eofbit); __in.width(0); } diff --git a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc index 0e98dced1082..7e449ab2fe48 100644 --- a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc +++ b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc @@ -551,6 +551,25 @@ test10() VERIFY( test ); } + +// libstdc++/8258 +class mybuf : public std::basic_streambuf +{ }; + +void test11() +{ + bool test = true; + using namespace std; + char arr[10]; + mybuf sbuf; + basic_istream > istr(&sbuf); + + VERIFY(istr.rdstate() == ios_base::goodbit); + VERIFY(istr.readsome(arr, 10) == 0); + VERIFY(istr.rdstate() == ios_base::goodbit); +} + + int main() { @@ -564,6 +583,6 @@ main() test08(); test09(); test10(); - + test11(); return 0; }