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++/16956


Paolo Carlini wrote:

Therefore, I'm finally coming to the conclusion that we have "just" a serious bug: I'm preparing a variant
of submitter patch + testcases, which will post soon.

This is the actual patch, already tested x86-linux. Interestingly, the current code is quite a bit cleaner than
the buggy one, thanks to __off added once and for all at beginning.


If nobody objects will commit to mainline this evening.

Paolo.

/////////////////////
2004-08-12  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/16956
	* include/bits/sstream.tcc (basic_stringbuf<>::seekoff): Add __off
	to the returned value, reorganize a bit.
	* testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc: New.
	* testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc: New.

	* testsuite/27_io/basic_stringbuf/seekoff/char/1.cc: Remove junk.
	* testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/seekpos/char/1.cc: Likewise.
	* testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc: Likewise.
diff -prN libstdc++-v3-orig/include/bits/sstream.tcc libstdc++-v3/include/bits/sstream.tcc
*** libstdc++-v3-orig/include/bits/sstream.tcc	Wed Jul  7 23:48:00 2004
--- libstdc++-v3/include/bits/sstream.tcc	Thu Aug 12 02:12:06 2004
***************
*** 1,6 ****
  // String based streams -*- C++ -*-
  
! // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
  // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
--- 1,6 ----
  // String based streams -*- C++ -*-
  
! // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2004
  // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
*************** namespace std
*** 147,174 ****
  
  	  _M_update_egptr();
  
! 	  off_type __newoffi = 0;
! 	  off_type __newoffo = 0;
  	  if (__way == ios_base::cur)
  	    {
! 	      __newoffi = this->gptr() - __beg;
! 	      __newoffo = this->pptr() - __beg;
  	    }
  	  else if (__way == ios_base::end)
! 	    __newoffo = __newoffi = this->egptr() - __beg;
  
  	  if ((__testin || __testboth)
! 	      && __newoffi + __off >= 0
! 	      && this->egptr() - __beg >= __newoffi + __off)
  	    {
! 	      this->gbump((__beg + __newoffi + __off) - this->gptr());
  	      __ret = pos_type(__newoffi);
  	    }
  	  if ((__testout || __testboth)
! 	      && __newoffo + __off >= 0
! 	      && this->egptr() - __beg >= __newoffo + __off)
  	    {
! 	      this->pbump((__beg + __newoffo + __off) - this->pptr());
  	      __ret = pos_type(__newoffo);
  	    }
  	}
--- 147,174 ----
  
  	  _M_update_egptr();
  
! 	  off_type __newoffi = __off;
! 	  off_type __newoffo = __newoffi;
  	  if (__way == ios_base::cur)
  	    {
! 	      __newoffi += this->gptr() - __beg;
! 	      __newoffo += this->pptr() - __beg;
  	    }
  	  else if (__way == ios_base::end)
! 	    __newoffo = __newoffi += this->egptr() - __beg;
  
  	  if ((__testin || __testboth)
! 	      && __newoffi >= 0
! 	      && this->egptr() - __beg >= __newoffi)
  	    {
! 	      this->gbump((__beg + __newoffi) - this->gptr());
  	      __ret = pos_type(__newoffi);
  	    }
  	  if ((__testout || __testboth)
! 	      && __newoffo >= 0
! 	      && this->egptr() - __beg >= __newoffo)
  	    {
! 	      this->pbump((__beg + __newoffo) - this->pptr());
  	      __ret = pos_type(__newoffo);
  	    }
  	}
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc	Fri Oct 17 00:37:52 2003
--- libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc	Thu Aug 12 02:29:15 2004
***************
*** 1,6 ****
  // 981208 bkoz test functionality of basic_stringbuf for char_type == char
  
! // 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
--- 1,6 ----
  // 981208 bkoz test functionality of basic_stringbuf for char_type == char
  
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
  // Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library is free
***************
*** 23,40 ****
  #include <testsuite_hooks.h>
  
  std::string str_01("mykonos. . . or what?");
- std::string str_02("paris, or sainte-maxime?");
- std::string str_03;
  std::stringbuf strb_01(str_01);
- std::stringbuf strb_02(str_02, std::ios_base::in);
- std::stringbuf strb_03(str_03, std::ios_base::out);
  
  // test overloaded virtual functions
  void test04() 
  {
    bool test __attribute__((unused)) = true;
    std::string 		str_tmp;
-   std::stringbuf 		strb_tmp;
    std::streamsize 		strmsz_1, strmsz_2;
    typedef std::stringbuf::int_type int_type;
    typedef std::stringbuf::traits_type traits_type;
--- 23,35 ----
*************** void test04() 
*** 42,53 ****
    typedef std::stringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2 = strb_02.sbumpc();
!   int_type c3 = strb_01.sbumpc();
  
-   // PUT
-   strb_03.str(str_01); //reset
-   
    // BUFFER MANAGEMENT & POSITIONING
  
    // seekoff
--- 37,44 ----
    typedef std::stringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2, c3;
  
    // BUFFER MANAGEMENT & POSITIONING
  
    // seekoff
*************** void test04() 
*** 58,65 ****
    off_type off_1 = 0;
    off_type off_2 = 0;
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
!   strb_02.str(str_02); //in ("paris, or sainte-maxime?");
!   strb_03.str(str_03); //out ("")
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
--- 49,55 ----
    off_type off_1 = 0;
    off_type off_2 = 0;
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
! 
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc	Thu Aug 12 02:09:07 2004
***************
*** 0 ****
--- 1,61 ----
+ // 2004-08-12  Paolo Carlini  <pcarlini@suse.de>
+ 
+ // Copyright (C) 2004 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library.  This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 27.7.1.3 Overridden virtual functions
+ 
+ #include <sstream>
+ #include <testsuite_hooks.h>
+ 
+ // libstdc++/16956
+ void test01()
+ {
+   bool test __attribute__((unused)) = true;
+   using namespace std;
+ 
+   typedef stringbuf::int_type int_type;
+   typedef stringbuf::traits_type traits_type;
+   typedef stringbuf::pos_type pos_type;
+   typedef stringbuf::off_type off_type;
+ 
+   stringbuf strb_01("lara's place", ios_base::in);
+   pos_type pt_1 = strb_01.pubseekoff(5, ios_base::cur, ios_base::in);
+   int_type c1 = strb_01.sgetc();
+   VERIFY( c1 != traits_type::eof() );
+   pos_type pt_2 = strb_01.pubseekoff(2, ios_base::cur, ios_base::in);
+   pos_type pt_3 = strb_01.pubseekpos(pt_1, ios_base::in);
+   int_type c2 = strb_01.sbumpc();
+   VERIFY( off_type(pt_3) == off_type(pt_2) - 2 );
+   VERIFY( c2 == c1 );
+ 
+   stringbuf strb_02("-", ios_base::out);
+   pos_type pt_4 = strb_02.pubseekoff(0, ios_base::cur, ios_base::out);
+   strb_02.sputn("red", 3);
+   pos_type pt_5 = strb_02.pubseekoff(-3, ios_base::cur, ios_base::out);
+   strb_02.pubseekpos(pt_5, ios_base::out);
+   VERIFY( off_type(pt_5) == off_type(pt_4) );
+   strb_02.sputn("blu", 3);
+   VERIFY( strb_02.str() == "blu" );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc	Sat Jul 10 00:00:55 2004
--- libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc	Thu Aug 12 02:29:43 2004
***************
*** 23,40 ****
  #include <testsuite_hooks.h>
  
  std::wstring str_01(L"mykonos. . . or what?");
- std::wstring str_02(L"paris, or sainte-maxime?");
- std::wstring str_03;
  std::wstringbuf strb_01(str_01);
- std::wstringbuf strb_02(str_02, std::ios_base::in);
- std::wstringbuf strb_03(str_03, std::ios_base::out);
  
  // test overloaded virtual functions
  void test04() 
  {
    bool test __attribute__((unused)) = true;
    std::wstring 		str_tmp;
-   std::wstringbuf 		strb_tmp;
    std::streamsize 		strmsz_1, strmsz_2;
    typedef std::wstringbuf::int_type int_type;
    typedef std::wstringbuf::traits_type traits_type;
--- 23,35 ----
*************** void test04() 
*** 42,52 ****
    typedef std::wstringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2 = strb_02.sbumpc();
!   int_type c3 = strb_01.sbumpc();
! 
!   // PUT
!   strb_03.str(str_01); //reset
    
    // BUFFER MANAGEMENT & POSITIONING
  
--- 37,43 ----
    typedef std::wstringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2, c3;
    
    // BUFFER MANAGEMENT & POSITIONING
  
*************** void test04() 
*** 58,65 ****
    off_type off_1 = 0;
    off_type off_2 = 0;
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
!   strb_02.str(str_02); //in ("paris, or sainte-maxime?");
!   strb_03.str(str_03); //out ("")
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
--- 49,55 ----
    off_type off_1 = 0;
    off_type off_2 = 0;
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
! 
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc	Thu Jan  1 01:00:00 1970
--- libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc	Thu Aug 12 02:10:13 2004
***************
*** 0 ****
--- 1,61 ----
+ // 2004-08-12  Paolo Carlini  <pcarlini@suse.de>
+ 
+ // Copyright (C) 2004 Free Software Foundation, Inc.
+ //
+ // This file is part of the GNU ISO C++ Library.  This library is free
+ // software; you can redistribute it and/or modify it under the
+ // terms of the GNU General Public License as published by the
+ // Free Software Foundation; either version 2, or (at your option)
+ // any later version.
+ 
+ // This library is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ // GNU General Public License for more details.
+ 
+ // You should have received a copy of the GNU General Public License along
+ // with this library; see the file COPYING.  If not, write to the Free
+ // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 27.7.1.3 Overridden virtual functions
+ 
+ #include <sstream>
+ #include <testsuite_hooks.h>
+ 
+ // libstdc++/16956
+ void test01()
+ {
+   bool test __attribute__((unused)) = true;
+   using namespace std;
+ 
+   typedef wstringbuf::int_type int_type;
+   typedef wstringbuf::traits_type traits_type;
+   typedef wstringbuf::pos_type pos_type;
+   typedef wstringbuf::off_type off_type;
+ 
+   wstringbuf strb_01(L"lara's place", ios_base::in);
+   pos_type pt_1 = strb_01.pubseekoff(5, ios_base::cur, ios_base::in);
+   int_type c1 = strb_01.sgetc();
+   VERIFY( c1 != traits_type::eof() );
+   pos_type pt_2 = strb_01.pubseekoff(2, ios_base::cur, ios_base::in);
+   pos_type pt_3 = strb_01.pubseekpos(pt_1, ios_base::in);
+   int_type c2 = strb_01.sbumpc();
+   VERIFY( off_type(pt_3) == off_type(pt_2) - 2 );
+   VERIFY( c2 == c1 );
+ 
+   wstringbuf strb_02(L"-", ios_base::out);
+   pos_type pt_4 = strb_02.pubseekoff(0, ios_base::cur, ios_base::out);
+   strb_02.sputn(L"red", 3);
+   pos_type pt_5 = strb_02.pubseekoff(-3, ios_base::cur, ios_base::out);
+   strb_02.pubseekpos(pt_5, ios_base::out);
+   VERIFY( off_type(pt_5) == off_type(pt_4) );
+   strb_02.sputn(L"blu", 3);
+   VERIFY( strb_02.str() == L"blu" );
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc	Fri Oct 17 00:37:53 2003
--- libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc	Thu Aug 12 02:25:51 2004
***************
*** 23,56 ****
  #include <testsuite_hooks.h>
  
  std::string str_01("mykonos. . . or what?");
- std::string str_02("paris, or sainte-maxime?");
- std::string str_03;
  std::stringbuf strb_01(str_01);
- std::stringbuf strb_02(str_02, std::ios_base::in);
- std::stringbuf strb_03(str_03, std::ios_base::out);
  
  // test overloaded virtual functions
  void test04() 
  {
    bool test __attribute__((unused)) = true;
    std::string 		str_tmp;
-   std::stringbuf 		strb_tmp;
    typedef std::stringbuf::int_type int_type;
-   typedef std::stringbuf::traits_type traits_type;
    typedef std::stringbuf::pos_type pos_type;
    typedef std::stringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2 = strb_02.sbumpc();
    int_type c3 = strb_01.sbumpc();
  
    pos_type pt_1(off_type(-1));
    pos_type pt_2(off_type(0));
    off_type off_1 = 0;
    off_type off_2 = 0;
- 
-   // PUT
-   strb_03.str(str_01); //reset
    
    // BUFFER MANAGEMENT & POSITIONING
  
--- 23,47 ----
  #include <testsuite_hooks.h>
  
  std::string str_01("mykonos. . . or what?");
  std::stringbuf strb_01(str_01);
  
  // test overloaded virtual functions
  void test04() 
  {
    bool test __attribute__((unused)) = true;
    std::string 		str_tmp;
    typedef std::stringbuf::int_type int_type;
    typedef std::stringbuf::pos_type pos_type;
    typedef std::stringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2; 
    int_type c3 = strb_01.sbumpc();
  
    pos_type pt_1(off_type(-1));
    pos_type pt_2(off_type(0));
    off_type off_1 = 0;
    off_type off_2 = 0;
    
    // BUFFER MANAGEMENT & POSITIONING
  
*************** void test04() 
*** 58,65 ****
    // pubseekpos(pos_type sp, ios_base::openmode)
    // alters the stream position to sp
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
!   strb_02.str(str_02); //in ("paris, or sainte-maxime?");
!   strb_03.str(str_03); //out ("")
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
--- 49,55 ----
    // pubseekpos(pos_type sp, ios_base::openmode)
    // alters the stream position to sp
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
! 
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc	Sat Jul 10 00:00:56 2004
--- libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc	Thu Aug 12 02:26:47 2004
***************
*** 23,47 ****
  #include <testsuite_hooks.h>
  
  std::wstring str_01(L"mykonos. . . or what?");
- std::wstring str_02(L"paris, or sainte-maxime?");
- std::wstring str_03;
  std::wstringbuf strb_01(str_01);
- std::wstringbuf strb_02(str_02, std::ios_base::in);
- std::wstringbuf strb_03(str_03, std::ios_base::out);
  
  // test overloaded virtual functions
  void test04() 
  {
    bool test __attribute__((unused)) = true;
    std::wstring 		str_tmp;
-   std::wstringbuf 		strb_tmp;
    typedef std::wstringbuf::int_type int_type;
-   typedef std::wstringbuf::traits_type traits_type;
    typedef std::wstringbuf::pos_type pos_type;
    typedef std::wstringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2 = strb_02.sbumpc();
    int_type c3 = strb_01.sbumpc();
  
    pos_type pt_1(off_type(-1));
--- 23,41 ----
  #include <testsuite_hooks.h>
  
  std::wstring str_01(L"mykonos. . . or what?");
  std::wstringbuf strb_01(str_01);
  
  // test overloaded virtual functions
  void test04() 
  {
    bool test __attribute__((unused)) = true;
    std::wstring 		str_tmp;
    typedef std::wstringbuf::int_type int_type;
    typedef std::wstringbuf::pos_type pos_type;
    typedef std::wstringbuf::off_type off_type;
  
    int_type c1 = strb_01.sbumpc();
!   int_type c2;
    int_type c3 = strb_01.sbumpc();
  
    pos_type pt_1(off_type(-1));
*************** void test04() 
*** 49,65 ****
    off_type off_1 = 0;
    off_type off_2 = 0;
  
-   // PUT
-   strb_03.str(str_01); //reset
-   
    // BUFFER MANAGEMENT & POSITIONING
  
    // seekpos
    // pubseekpos(pos_type sp, ios_base::openmode)
    // alters the stream position to sp
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
!   strb_02.str(str_02); //in ("paris, or sainte-maxime?");
!   strb_03.str(str_03); //out ("")
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
--- 43,55 ----
    off_type off_1 = 0;
    off_type off_2 = 0;
  
    // BUFFER MANAGEMENT & POSITIONING
  
    // seekpos
    // pubseekpos(pos_type sp, ios_base::openmode)
    // alters the stream position to sp
    strb_01.str(str_01); //in|out ("mykonos. . . or what?");
! 
    //IN|OUT
    //beg
    pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);

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