You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by fa...@apache.org on 2007/12/19 16:30:00 UTC

svn commit: r605583 - /incubator/stdcxx/trunk/include/istream.cc

Author: faridz
Date: Wed Dec 19 07:29:58 2007
New Revision: 605583

URL: http://svn.apache.org/viewvc?rev=605583&view=rev
Log:
2007-12-19 Farid Zaripov <fa...@epam.com>

	Merged r605577 from branches/4.2.x with a fix for STDCXX-250
	* 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/trunk/include/istream.cc

Modified: incubator/stdcxx/trunk/include/istream.cc
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/include/istream.cc?rev=605583&r1=605582&r2=605583&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/istream.cc (original)
+++ incubator/stdcxx/trunk/include/istream.cc Wed Dec 19 07:29:58 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);