Blame SOURCES/gcc48-pr81395.patch

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