This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Fix libstdc++/9538


Hi again,

this one too, seems quite straightforward: we had better
accessing this->gptr()[-1] only when _M_in_beg < _M_in_cur.

Many thanks to Pétur for nice reports and testcases!

Tested x86-linux, ok for trunk and 3.3?

Paolo.

////////////////
2003-02-02  Paolo Carlini  <pcarlini@unitus.it>

	* include/bits/streambuf.tcc (sputbackc): Access
	this->gptr()[-1] only if _M_in_beg < _M_in_cur.
	* testsuite/27_io/filebuf_virtuals.cc (test08): Add.
diff -urN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
--- libstdc++-v3-orig/include/bits/streambuf.tcc	2002-12-16 19:22:59.000000000 +0100
+++ libstdc++-v3/include/bits/streambuf.tcc	2003-02-02 19:48:57.000000000 +0100
@@ -67,8 +67,7 @@
     {
       int_type __ret;
       bool __testpos = _M_in_cur && _M_in_beg < _M_in_cur;
-      bool __testne = _M_in_cur && !traits_type::eq(__c, this->gptr()[-1]);
-      if (!__testpos || __testne)
+      if (!__testpos || !traits_type::eq(__c, this->gptr()[-1]))
 	__ret = this->pbackfail(traits_type::to_int_type(__c));
       else 
 	{
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-01-23 23:53:35.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc	2003-02-02 20:02:54.000000000 +0100
@@ -537,6 +537,39 @@
   VERIFY( ob.getloc() == loc_de );
 }
 
+class MyTraits : public std::char_traits<char>
+{
+public:
+  static bool eq(char c1, char c2)
+  {
+    VERIFY( c1 >= 0 );
+    VERIFY( c2 >= 0 );
+    return std::char_traits<char>::eq(c1, c2);
+  }
+};
+
+class MyBuf : public std::basic_streambuf<char, MyTraits>
+{
+  char buffer[8];
+
+public:
+  MyBuf()
+  {
+    std::memset(buffer, -1, sizeof(buffer));
+    std::memset(buffer + 2, 0, 4);
+    setg(buffer + 2, buffer + 2, buffer + 6);
+  }
+};
+
+// libstdc++/9538
+void test08()
+{
+  bool test = true;
+
+  MyBuf mb;
+  mb.sputbackc(0);  
+}
+
 main() 
 {
   test01();
@@ -548,5 +581,6 @@
   test06();
 
   test07();
+  test08();
   return 0;
 }

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