|
|
5ed81e |
2017-07-18 Jonathan Wakely <jwakely@redhat.com>
|
|
|
5ed81e |
|
|
|
5ed81e |
PR libstdc++/81395
|
|
|
5ed81e |
* include/bits/fstream.tcc (basic_filebuf::xsgetn): Don't set buffer
|
|
|
5ed81e |
pointers for write mode after reading.
|
|
|
5ed81e |
* testsuite/27_io/basic_filebuf/sgetn/char/81395.cc: New.
|
|
|
5ed81e |
|
|
|
5ed81e |
--- libstdc++-v3/include/bits/fstream.tcc (revision 254017)
|
|
|
5ed81e |
+++ libstdc++-v3/include/bits/fstream.tcc (revision 254018)
|
|
|
5ed81e |
@@ -699,7 +699,7 @@
|
|
|
5ed81e |
|
|
|
5ed81e |
if (__n == 0)
|
|
|
5ed81e |
{
|
|
|
5ed81e |
- _M_set_buffer(0);
|
|
|
5ed81e |
+ // Set _M_reading. Buffer is already in initial 'read' mode.
|
|
|
5ed81e |
_M_reading = true;
|
|
|
5ed81e |
}
|
|
|
5ed81e |
else if (__len == 0)
|
|
|
5ed81e |
--- libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/81395.cc (nonexistent)
|
|
|
5ed81e |
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/81395.cc (revision 254018)
|
|
|
5ed81e |
@@ -0,0 +1,46 @@
|
|
|
5ed81e |
+// Copyright (C) 2017 Free Software Foundation, Inc.
|
|
|
5ed81e |
+//
|
|
|
5ed81e |
+// This file is part of the GNU ISO C++ Library. This library is free
|
|
|
5ed81e |
+// software; you can redistribute it and/or modify it under the
|
|
|
5ed81e |
+// terms of the GNU General Public License as published by the
|
|
|
5ed81e |
+// Free Software Foundation; either version 3, or (at your option)
|
|
|
5ed81e |
+// any later version.
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+// This library is distributed in the hope that it will be useful,
|
|
|
5ed81e |
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
5ed81e |
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
5ed81e |
+// GNU General Public License for more details.
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+// You should have received a copy of the GNU General Public License along
|
|
|
5ed81e |
+// with this library; see the file COPYING3. If not see
|
|
|
5ed81e |
+// <http://www.gnu.org/licenses/>.
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+// { dg-require-fileio "" }
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+// PR libstdc++/81395
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+#include <fstream>
|
|
|
5ed81e |
+#include <cstring> // for std::memset
|
|
|
5ed81e |
+#include <cstdio> // For BUFSIZ
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+using std::memset;
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+int main()
|
|
|
5ed81e |
+{
|
|
|
5ed81e |
+ {
|
|
|
5ed81e |
+ std::filebuf fb;
|
|
|
5ed81e |
+ fb.open("test.txt", std::ios::out);
|
|
|
5ed81e |
+ char data[BUFSIZ];
|
|
|
5ed81e |
+ memset(data, 'A', sizeof(data));
|
|
|
5ed81e |
+ fb.sputn(data, sizeof(data));
|
|
|
5ed81e |
+ }
|
|
|
5ed81e |
+
|
|
|
5ed81e |
+ std::filebuf fb;
|
|
|
5ed81e |
+ fb.open("test.txt", std::ios::in|std::ios::out);
|
|
|
5ed81e |
+ char buf[BUFSIZ];
|
|
|
5ed81e |
+ memset(buf, 0, sizeof(buf));
|
|
|
5ed81e |
+ fb.sgetn(buf, sizeof(buf));
|
|
|
5ed81e |
+ // Switch from reading to writing without seeking first:
|
|
|
5ed81e |
+ fb.sputn("B", 1);
|
|
|
5ed81e |
+ fb.pubsync();
|
|
|
5ed81e |
+}
|