Blame SOURCES/gcc48-pr81395.patch

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