OSDN Git Service

2003-06-05 Paolo Carlini <pcarlini@unitus.it>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 5 Jun 2003 23:25:05 +0000 (23:25 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 5 Jun 2003 23:25:05 +0000 (23:25 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@67518 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/include/bits/ostream.tcc
libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc [new file with mode: 0644]

index a76d385..8026421 100644 (file)
@@ -1,3 +1,22 @@
+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.
+
 2003-06-05  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
 
        * acinclude.m4 (GLIBCPP_CHECK_PCH): Only set glibcpp_PCHFLAGS if
index a9448b0..eaeb414 100644 (file)
@@ -1021,7 +1021,7 @@ namespace std
            {
              // 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());
index 6204588..b71bdb8 100644 (file)
@@ -474,7 +474,7 @@ namespace std
        {
          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 @@ namespace std
        {
          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 @@ namespace std
        {
          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 @@ namespace std
          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 @@ namespace std
        {
          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 @@ namespace std
       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 --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc
new file mode 100644 (file)
index 0000000..ec25ebc
--- /dev/null
@@ -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 --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc
new file mode 100644 (file)
index 0000000..d9158f5
--- /dev/null
@@ -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;
+
+  oss_01.width(-60);
+  oss_01 << 'C';
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == "C" );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc
new file mode 100644 (file)
index 0000000..f208723
--- /dev/null
@@ -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;
+
+  oss_01.width(-60);
+  oss_01 << "Consoli";
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == "Consoli" );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc
new file mode 100644 (file)
index 0000000..204089d
--- /dev/null
@@ -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;
+
+  oss_01.width(-60);
+  oss_01 << std::string("Consoli");
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == "Consoli" );
+}
+
+int main()
+{
+  test03();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc
new file mode 100644 (file)
index 0000000..bd4d184
--- /dev/null
@@ -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;
+
+  oss_01.width(-60);
+  oss_01 << L'C';
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == L"C" );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc
new file mode 100644 (file)
index 0000000..4be5d86
--- /dev/null
@@ -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;
+
+  oss_01.width(-60);
+  oss_01 << L"Consoli";
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == L"Consoli" );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc
new file mode 100644 (file)
index 0000000..34695a4
--- /dev/null
@@ -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;
+
+  oss_01.width(-60);
+  oss_01 << "Consoli";
+  VERIFY( oss_01.good() );
+  VERIFY( oss_01.str() == L"Consoli" );
+}
+
+int main()
+{
+  test03();
+  return 0;
+}