summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-06-05 23:25:05 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-06-05 23:25:05 +0000
commitae8ad3ad36048f2301ed257b04ff08918bb2112d (patch)
tree2f310681a5057950759e7b4c3f1d1ab9c6a352dc
parent14ba6a985c96dcd8e28088b541a5e800a3a97135 (diff)
downloadgcc-ae8ad3ad36048f2301ed257b04ff08918bb2112d.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@67518 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/ChangeLog19
-rw-r--r--libstdc++-v3/include/bits/istream.tcc2
-rw-r--r--libstdc++-v3/include/bits/ostream.tcc12
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc55
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc46
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc46
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc46
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc46
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc46
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc46
10 files changed, 357 insertions, 7 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index a76d385fd6e..8026421a5fe 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc
index a9448b09c09..eaeb414678f 100644
--- a/libstdc++-v3/include/bits/istream.tcc
+++ b/libstdc++-v3/include/bits/istream.tcc
@@ -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());
diff --git a/libstdc++-v3/include/bits/ostream.tcc b/libstdc++-v3/include/bits/ostream.tcc
index 620458806a1..b71bdb835d2 100644
--- a/libstdc++-v3/include/bits/ostream.tcc
+++ b/libstdc++-v3/include/bits/ostream.tcc
@@ -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
index 00000000000..ec25ebcaa4d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc
@@ -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
index 00000000000..d9158f534f0
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc
@@ -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
index 00000000000..f208723de8a
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc
@@ -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
index 00000000000..204089df14f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc
@@ -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
index 00000000000..bd4d1840fd7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc
@@ -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
index 00000000000..4be5d86feb9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc
@@ -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
index 00000000000..34695a4314f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc
@@ -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;
+}