Author: faridz
Date: Wed Dec 19 07:26:47 2007
New Revision: 605577

URL: http://svn.apache.org/viewvc?rev=605577&view=rev
Log:
2007-12-19 Farid Zaripov <[EMAIL PROTECTED]>

        STDCXX-226
        * istream.cc (operator>>): Move counter __i out from the try/catch block
        and rename to __gcount for consistency with getline(). Increment 
__gcount
        after sbumpc() but before sgetc() to correctly reflect the number of 
        extracted characters. Set ios_base::failbit if no characters extracted.

Modified:
    incubator/stdcxx/branches/4.2.x/include/istream.cc

Modified: incubator/stdcxx/branches/4.2.x/include/istream.cc
URL: 
http://svn.apache.org/viewvc/incubator/stdcxx/branches/4.2.x/include/istream.cc?rev=605577&r1=605576&r2=605577&view=diff
==============================================================================
--- incubator/stdcxx/branches/4.2.x/include/istream.cc (original)
+++ incubator/stdcxx/branches/4.2.x/include/istream.cc Wed Dec 19 07:26:47 2007
@@ -790,6 +790,8 @@
 
     ios_base::iostate __err = ios_base::goodbit;
 
+    _RWSTD_SIZE_T __gcount = 0;
+
     _TRY {
 
         const _TYPENAME basic_istream<_CharT, _Traits>::sentry
@@ -808,14 +810,16 @@
             const _RWSTD_SIZE_T __maxlen =
                 __is.width () ? __is.width () : __str.max_size ();
 
-            _RWSTD_SIZE_T __i = 0;
-
             __str.erase ();
 
             const ctype<_CharT> &__ctp =
                 _USE_FACET (ctype<_CharT>, __is.getloc ());
 
-            for ( ; __maxlen != __i; ++__i, __rdbuf->sbumpc ()) {
+            // increment gcount only _after_ sbumpc() but _before_
+            // the subsequent call to sgetc() to correctly reflect
+            // the number of extracted characters in the presence
+            // of exceptions thrown from streambuf virtuals
+            for ( ; __maxlen != __gcount; __rdbuf->sbumpc (), ++__gcount) {
 
                 const _TYPENAME _Traits::int_type __c (__rdbuf->sgetc ());
 
@@ -835,14 +839,14 @@
             }
 
             __is.width (0);
-
-            if (!__i)
-                __err |= ios_base::failbit;
         }
     }
     _CATCH (...) {
         __is.setstate (__is.badbit | _RW::__rw_rethrow);
     }
+
+    if (!__gcount)
+        __err |= ios_base::failbit;
 
     if (__err)
         __is.setstate (__err);


Reply via email to