Blame SOURCES/gcc48-pr81395.patch

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