Author: sebor
Date: Thu Oct 27 15:27:53 2005
New Revision: 328966

URL: http://svn.apache.org/viewcvs?rev=328966&view=rev
Log:
2005-10-27  Martin Sebor  <[EMAIL PROTECTED]>

        STDCXX-59
        * istream.cc (getline): On failure, stored the NUL character
        in the first location of the array as required by DR 243.
        Prevented the function from overwriting extracted data or storing
        the NUL character past the end of buffer.

Modified:
    incubator/stdcxx/trunk/include/istream.cc

Modified: incubator/stdcxx/trunk/include/istream.cc
URL: 
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/istream.cc?rev=328966&r1=328965&r2=328966&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/istream.cc (original)
+++ incubator/stdcxx/trunk/include/istream.cc Thu Oct 27 15:27:53 2005
@@ -670,6 +670,12 @@
     _RWSTD_ASSERT (!__n || __s);
     _RWSTD_ASSERT (0 != this->rdbuf ());
 
+    if (0 < __n) {
+        // lwg issue 243: store the NUL character before
+        // constructing the sentry object in case it throws
+        traits_type::assign (__s [0], char_type ());
+    }
+
     const sentry __ipfx (*this, true /* noskipws */);
 
     ios_base::iostate __err = ios_base::goodbit;
@@ -770,9 +776,9 @@
         }
     }
 
-    traits_type::assign (__s [__n < 0 ? 0 : __n], char_type ());
-
-    if (!_C_gcount)
+    if (0 < _C_gcount)
+        traits_type::assign (__s [_C_gcount + 1], char_type ());
+    else
         __err |= ios_base::failbit;
 
     if (__err)


Reply via email to