From 05fd6e9086147dd35deccecf6b0a193684cf90c5 Mon Sep 17 00:00:00 2001
From: paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 12 Aug 2004 22:26:32 +0000
Subject: [PATCH] 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.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85910 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libstdc++-v3/ChangeLog                        | 13 ++++
 libstdc++-v3/include/bits/sstream.tcc         | 24 ++++----
 .../27_io/basic_stringbuf/seekoff/char/1.cc   | 16 +----
 .../basic_stringbuf/seekoff/char/16956.cc     | 61 +++++++++++++++++++
 .../basic_stringbuf/seekoff/wchar_t/1.cc      | 14 +----
 .../basic_stringbuf/seekoff/wchar_t/16956.cc  | 61 +++++++++++++++++++
 .../27_io/basic_stringbuf/seekpos/char/1.cc   | 14 +----
 .../basic_stringbuf/seekpos/wchar_t/1.cc      | 14 +----
 8 files changed, 156 insertions(+), 61 deletions(-)
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc
 create mode 100644 libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index a4474c9dcad3..512f1643709e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,16 @@
+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.
+
 2004-08-12  Paul Brook  <paul@codesourcery.com>
 
 	* config/cpu/arm/cxxabi_tweaks.h: Define __cxa_vec_ctor_return and
diff --git a/libstdc++-v3/include/bits/sstream.tcc b/libstdc++-v3/include/bits/sstream.tcc
index 04cd6ec92a29..137d6b3fff77 100644
--- a/libstdc++-v3/include/bits/sstream.tcc
+++ b/libstdc++-v3/include/bits/sstream.tcc
@@ -1,6 +1,6 @@
 // String based streams -*- C++ -*-
 
-// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
+// 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
@@ -147,28 +147,28 @@ namespace std
 
 	  _M_update_egptr();
 
-	  off_type __newoffi = 0;
-	  off_type __newoffo = 0;
+	  off_type __newoffi = __off;
+	  off_type __newoffo = __newoffi;
 	  if (__way == ios_base::cur)
 	    {
-	      __newoffi = this->gptr() - __beg;
-	      __newoffo = this->pptr() - __beg;
+	      __newoffi += this->gptr() - __beg;
+	      __newoffo += this->pptr() - __beg;
 	    }
 	  else if (__way == ios_base::end)
-	    __newoffo = __newoffi = this->egptr() - __beg;
+	    __newoffo = __newoffi += this->egptr() - __beg;
 
 	  if ((__testin || __testboth)
-	      && __newoffi + __off >= 0
-	      && this->egptr() - __beg >= __newoffi + __off)
+	      && __newoffi >= 0
+	      && this->egptr() - __beg >= __newoffi)
 	    {
-	      this->gbump((__beg + __newoffi + __off) - this->gptr());
+	      this->gbump((__beg + __newoffi) - this->gptr());
 	      __ret = pos_type(__newoffi);
 	    }
 	  if ((__testout || __testboth)
-	      && __newoffo + __off >= 0
-	      && this->egptr() - __beg >= __newoffo + __off)
+	      && __newoffo >= 0
+	      && this->egptr() - __beg >= __newoffo)
 	    {
-	      this->pbump((__beg + __newoffo + __off) - this->pptr());
+	      this->pbump((__beg + __newoffo) - this->pptr());
 	      __ret = pos_type(__newoffo);
 	    }
 	}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
index 08e5afbce51a..70d2fd6b3afb 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
@@ -1,6 +1,6 @@
 // 981208 bkoz test functionality of basic_stringbuf for char_type == char
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+// 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,18 +23,13 @@
 #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;
@@ -42,12 +37,8 @@ void test04()
   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();
+  int_type c2, c3;
 
-  // PUT
-  strb_03.str(str_01); //reset
-  
   // BUFFER MANAGEMENT & POSITIONING
 
   // seekoff
@@ -58,8 +49,7 @@ void test04()
   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);
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc
new file mode 100644
index 000000000000..8e85a03961f7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc
@@ -0,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 --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
index c1a659e6be1d..6177140c8034 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
@@ -23,18 +23,13 @@
 #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;
@@ -42,11 +37,7 @@ void test04()
   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
+  int_type c2, c3;
   
   // BUFFER MANAGEMENT & POSITIONING
 
@@ -58,8 +49,7 @@ void test04()
   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);
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc
new file mode 100644
index 000000000000..6b43b385cd15
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc
@@ -0,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 --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc
index c84dbcd47a77..2420a80106b3 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc
@@ -23,34 +23,25 @@
 #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 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;
-
-  // PUT
-  strb_03.str(str_01); //reset
   
   // BUFFER MANAGEMENT & POSITIONING
 
@@ -58,8 +49,7 @@ void test04()
   // 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);
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc
index bac614efa9fd..41850d9ea86a 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc
@@ -23,25 +23,19 @@
 #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 c2;
   int_type c3 = strb_01.sbumpc();
 
   pos_type pt_1(off_type(-1));
@@ -49,17 +43,13 @@ void test04()
   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);
-- 
GitLab