This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Fix libstdc++/10097


Hi,

tested x86-linux, approved by Benjamin.

Paolo.

//////////
2003-03-17  Paolo Carlini  <pcarlini at unitus dot it>
	    Petur Runolfsson  <peturr02 at ru dot is>

	PR libstdc++/10097
	* src/fstream.cc (basic_filebuf<char>::_M_underflow_common,
	basic_filebuf<wchar_t>::_M_underflow_common):
	if (gptr() < egptr()) return *gptr().
	* testsuite/27_io/filebuf_virtuals.cc (test16): Add.

	* testsuite/27_io/filebuf_members.cc (test_04): Minor
	changes: unlink fifo before making it, fix spelling error.
diff -urN libstdc++-v3-orig/src/fstream.cc libstdc++-v3/src/fstream.cc
--- libstdc++-v3-orig/src/fstream.cc	2003-03-09 23:55:04.000000000 +0100
+++ libstdc++-v3/src/fstream.cc	2003-03-18 00:22:50.000000000 +0100
@@ -1,6 +1,6 @@
 // File based streams -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -52,15 +52,14 @@
 	  // normal buffers and jet outta here before expensive
 	  // fileops happen...
 	  if (_M_pback_init)
+	    _M_pback_destroy();
+
+	  if (_M_in_cur && _M_in_cur < _M_in_end)
 	    {
-	      _M_pback_destroy();
-	      if (_M_in_cur < _M_in_end)
-		{
-		  __ret = traits_type::to_int_type(*_M_in_cur);
-		  if (__bump)
-		    _M_in_cur_move(1);
-		  return __ret;
-		}
+	      __ret = traits_type::to_int_type(*_M_in_cur);
+	      if (__bump)
+		_M_in_cur_move(1);
+	      return __ret;
 	    }
 
 	  // Sync internal and external buffers.
@@ -135,15 +134,14 @@
 	  // normal buffers and jet outta here before expensive
 	  // fileops happen...
 	  if (_M_pback_init)
+	    _M_pback_destroy();
+
+	  if (_M_in_cur && _M_in_cur < _M_in_end)
 	    {
-	      _M_pback_destroy();
-	      if (_M_in_cur < _M_in_end)
-		{
-		  __ret = traits_type::to_int_type(*_M_in_cur);
-		  if (__bump)
-		    _M_in_cur_move(1);
-	  	  return __ret;
-		}
+	      __ret = traits_type::to_int_type(*_M_in_cur);
+	      if (__bump)
+		_M_in_cur_move(1);
+	      return __ret;
 	    }
 
 	  // Sync internal and external buffers.
diff -urN libstdc++-v3-orig/testsuite/27_io/filebuf_members.cc libstdc++-v3/testsuite/27_io/filebuf_members.cc
--- libstdc++-v3-orig/testsuite/27_io/filebuf_members.cc	2003-03-18 00:19:57.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/filebuf_members.cc	2003-03-18 00:25:34.000000000 +0100
@@ -133,9 +133,10 @@
   const char* name = "tmp_fifo1";
   signal(SIGPIPE, SIG_IGN);
   
+  unlink(name);
   if (0 != mkfifo(name, S_IRWXU))
     {
-      std::cerr << "failed to creat fifo" << std::endl;
+      std::cerr << "failed to create fifo" << std::endl;
       exit(-1);
     }
   
diff -urN libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
--- libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc	2003-03-18 00:19:57.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc	2003-03-18 00:29:58.000000000 +0100
@@ -21,6 +21,11 @@
 // 27.8.1.4 Overridden virtual functions
 
 #include <fstream>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <locale>
 #include <testsuite_hooks.h>
 
@@ -798,6 +803,71 @@
   fbin.close();
 }
 
+class UnderBuf : public std::filebuf
+{
+public:
+  int_type
+  pub_underflow()
+  { return underflow(); }
+
+  std::streamsize
+  pub_showmanyc()
+  { return showmanyc(); }
+};
+
+// libstdc++/10097
+void test16()
+{
+  using namespace std;
+  bool test = true;
+
+  const char* name = "tmp_fifo1";
+  
+  signal(SIGPIPE, SIG_IGN);
+  unlink(name);
+  
+  if (0 != mkfifo(name, S_IRWXU))
+    {
+      VERIFY( false );
+    }
+  
+  int fval = fork();
+  if (fval == -1)
+    {
+      unlink(name);
+      VERIFY( false );
+    }
+  else if (fval == 0)
+    {
+      filebuf fbout;
+      fbout.open(name, ios_base::out);
+      fbout.sputn("0123456789", 10);
+      fbout.pubsync();
+      sleep(2);
+      fbout.close();
+      exit(0);
+    }
+
+  UnderBuf fb;
+  fb.open(name, ios_base::in);
+  sleep(1);
+  
+  fb.sgetc();
+  streamsize n = fb.pub_showmanyc();
+
+  while (n > 0)
+    {
+      --n;
+      
+      UnderBuf::int_type c = fb.pub_underflow();
+      VERIFY( c != UnderBuf::traits_type::eof() );
+      
+      fb.sbumpc();
+    }
+
+  fb.close();
+}
+
 main() 
 {
   test01();
@@ -817,5 +887,6 @@
   test13();
   test14();
   test15();
+  test16();
   return 0;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]