]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/8258 (basic_istream::readsome() with default buffer change stream...
authorBenjamin Kosnik <bkoz@redhat.com>
Wed, 6 Nov 2002 00:08:37 +0000 (00:08 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Wed, 6 Nov 2002 00:08:37 +0000 (00:08 +0000)
2002-11-05  Benjamin Kosnik  <bkoz@redhat.com>

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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/testsuite/27_io/istream_unformatted.cc

index 31a2e636d5a50a44ee808f5e9aa111d97bbdc357..c25f6e37d4a48553a8a3b36188eafa53e9984a7a 100644 (file)
@@ -1,3 +1,13 @@
+2002-11-05  Benjamin Kosnik  <bkoz@redhat.com>
+
+       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  <bkoz@redhat.com>
 
        PR libstdc++/7219
index 617110d953b8f4c804c2f7159ca64f3939724089..a6e49a923bd2fb027dc951c73fcb2a7c56e4d11e 100644 (file)
@@ -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);
        }
index 0e98dced1082028b08cc92cd1fc758fedfd001e3..7e449ab2fe481d222bec4979a5d425fadf32dcce 100644 (file)
@@ -551,6 +551,25 @@ test10()
   VERIFY( test );
 }
 
+
+// libstdc++/8258
+class mybuf : public std::basic_streambuf<char> 
+{ };
+
+void test11()
+{
+  bool test = true;
+  using namespace std;
+  char arr[10];
+  mybuf sbuf;
+  basic_istream<char, char_traits<char> > 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;
 }