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


Hi,

tested x86-linux, reviewed by Benjamin.
Will go in 3_3-branch too.

Paolo.

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

	PR libstdc++/11095
	* include/bits/istream.tcc (operator>>(basic_istream&, _CharT*)):
	Deal with width() smaller than zero.
	* include/bits/ostream.tcc (operator<<(basic_ostream&, _CharT),
	operator<<(basic_ostream&, char), operator<<(basic_ostream&,
	const _CharT*), operator<<(basic_ostream<_CharT, _Traits>&,
	const char*), operator<<(basic_ostream<char, _Traits>&,
	const char*), operator<<(basic_ostream, const basic_string&)): Likewise.
	* testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc:
	* testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc:
	* testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc:
	* testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc:
	* testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc:
	* testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc:
	* testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc:
	New.
	
diff -urN libstdc++-v3-orig/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
--- libstdc++-v3-orig/include/bits/istream.tcc	2003-05-13 22:13:14.000000000 +0200
+++ libstdc++-v3/include/bits/istream.tcc	2003-06-05 14:00:42.000000000 +0200
@@ -1021,7 +1021,7 @@
 	    {
 	      // Figure out how many characters to extract.
 	      streamsize __num = __in.width();
-	      if (__num == 0)
+	      if (__num <= 0)
 		__num = numeric_limits<streamsize>::max();
 	      
 	      const __ctype_type& __ctype = use_facet<__ctype_type>(__in.getloc());
diff -urN libstdc++-v3-orig/include/bits/ostream.tcc libstdc++-v3/include/bits/ostream.tcc
--- libstdc++-v3-orig/include/bits/ostream.tcc	2003-05-13 22:13:15.000000000 +0200
+++ libstdc++-v3/include/bits/ostream.tcc	2003-06-05 21:37:17.000000000 +0200
@@ -474,7 +474,7 @@
 	{
 	  try 
 	    {
-	      streamsize __w = __out.width();
+	      const streamsize __w = __out.width() > 0 ? __out.width() : 0;
 	      _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__w + 1)));
 	      __pads[0] = __c;
 	      streamsize __len = 1;
@@ -510,7 +510,7 @@
 	{
 	  try 
 	    {
-	      streamsize __w = __out.width();
+	      const streamsize __w = __out.width() > 0 ? __out.width() : 0;
 	      char* __pads = static_cast<char*>(__builtin_alloca(__w + 1));
 	      __pads[0] = __c;
 	      streamsize __len = 1;
@@ -545,7 +545,7 @@
 	{
 	  try 
 	    {
-	      streamsize __w = __out.width();
+	      const streamsize __w = __out.width() > 0 ? __out.width() : 0;
 	      _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
 	      streamsize __len = static_cast<streamsize>(_Traits::length(__s));
 	      if (__w > __len)
@@ -594,7 +594,7 @@
 	  try 
 	    {
 	      streamsize __len = static_cast<streamsize>(__clen);
-	      streamsize __w = __out.width();
+	      const streamsize __w = __out.width() > 0 ? __out.width() : 0;
 	      _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
 	      
 	      if (__w > __len)
@@ -632,7 +632,7 @@
 	{
 	  try 
 	    {
-	      streamsize __w = __out.width();
+	      const streamsize __w = __out.width() > 0 ? __out.width() : 0;
 	      char* __pads = static_cast<char*>(__builtin_alloca(__w));
 	      streamsize __len = static_cast<streamsize>(_Traits::length(__s));
 
@@ -671,7 +671,7 @@
       if (__cerb)
 	{
 	  const _CharT* __s = __str.data();
-	  streamsize __w = __out.width();
+	  const streamsize __w = __out.width() > 0 ? __out.width() : 0;
 	  _CharT* __pads = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w));
 	  streamsize __len = static_cast<streamsize>(__str.size());
 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc	2003-06-05 22:02:52.000000000 +0200
@@ -0,0 +1,55 @@
+// 2003-06-05 Paolo Carlini <pcarlini@unitus.it>
+ 
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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.6.1.2.3 character extractors
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/11095
+// operator>>(basic_istream&, _CharT*)
+void test01() 
+{
+  bool test = true;
+  const std::string str_01("Consoli ");
+
+  std::stringbuf isbuf_01(str_01, std::ios_base::in);
+  std::istream is_01(&isbuf_01);
+
+  std::ios_base::iostate state1, state2;
+
+  char array1[10];
+  typedef std::ios::traits_type ctraits_type;
+
+  is_01.width(-60);
+  state1 = is_01.rdstate();
+  is_01 >> array1;
+  state2 = is_01.rdstate();
+  VERIFY( state1 == state2 );
+  VERIFY( !ctraits_type::compare(array1, "Consoli", 7) );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc	2003-06-05 22:03:39.000000000 +0200
@@ -0,0 +1,46 @@
+// 2003-06-05  Paolo Carlini  <pcarlini@unitus.it>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/11095
+// operator<<(basic_ostream&, char)
+void
+test01() 
+{
+  bool test = true;
+
+  std::ostringstream oss_01(std::ios_base::out);
+
+  oss_01.width(-60);
+  oss_01 << 'C';
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == "C" );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc	2003-06-05 22:07:44.000000000 +0200
@@ -0,0 +1,46 @@
+// 2003-06-05  Paolo Carlini  <pcarlini@unitus.it>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/11095
+// operator<<(basic_ostream<char, _Traits>&, const char*)
+void
+test02() 
+{
+  bool test = true;
+
+  std::ostringstream oss_01(std::ios_base::out);
+
+  oss_01.width(-60);
+  oss_01 << "Consoli";
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == "Consoli" );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc	2003-06-05 22:11:32.000000000 +0200
@@ -0,0 +1,46 @@
+// 2003-06-05  Paolo Carlini  <pcarlini@unitus.it>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/11095
+// operator<<(basic_ostream&, const basic_string&)
+void
+test03() 
+{
+  bool test = true;
+
+  std::ostringstream oss_01(std::ios_base::out);
+
+  oss_01.width(-60);
+  oss_01 << std::string("Consoli");
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == "Consoli" );
+}
+
+int main()
+{
+  test03();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc	2003-06-05 22:05:08.000000000 +0200
@@ -0,0 +1,46 @@
+// 2003-06-05  Paolo Carlini  <pcarlini@unitus.it>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/11095
+// operator<<(basic_ostream&, _CharT)
+void
+test01() 
+{
+  bool test = true;
+
+  std::wostringstream oss_01(std::ios_base::out);
+
+  oss_01.width(-60);
+  oss_01 << L'C';
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == L"C" );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc	2003-06-05 22:05:58.000000000 +0200
@@ -0,0 +1,46 @@
+// 2003-06-05  Paolo Carlini  <pcarlini@unitus.it>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/11095
+// operator<<(basic_ostream&, const _CharT*)
+void
+test02() 
+{
+  bool test = true;
+
+  std::wostringstream oss_01(std::ios_base::out);
+
+  oss_01.width(-60);
+  oss_01 << L"Consoli";
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == L"Consoli" );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc	2003-06-05 22:06:45.000000000 +0200
@@ -0,0 +1,46 @@
+// 2003-06-05  Paolo Carlini  <pcarlini@unitus.it>
+
+// Copyright (C) 2003 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/11095
+// operator<<(basic_ostream<_CharT, _Traits>&, const char*)
+void
+test03() 
+{
+  bool test = true;
+
+  std::wostringstream oss_01(std::ios_base::out);
+
+  oss_01.width(-60);
+  oss_01 << "Consoli";
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == L"Consoli" );
+}
+
+int main()
+{
+  test03();
+  return 0;
+}

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