aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2009-02-15 16:47:57 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2009-02-15 16:47:57 +0000
commitbbcac3becb8dcc1cf5a8d65926ce15b296f4367c (patch)
treeeb15a978460c1aaecb4876c6b96497177e6ac71a /libstdc++-v3
parent68c9ab451b8163597dee5ed2f7ee23859b9b453a (diff)
downloadgcc-bbcac3becb8dcc1cf5a8d65926ce15b296f4367c.zip
gcc-bbcac3becb8dcc1cf5a8d65926ce15b296f4367c.tar.gz
gcc-bbcac3becb8dcc1cf5a8d65926ce15b296f4367c.tar.bz2
re PR libstdc++/39168 (Incorrect interpretation of CHAR_MAX inside grouping string in monetary and numeric facets.)
2009-02-15 Paolo Carlini <paolo.carlini@oracle.com> PR libstdc++/39168 * src/locale_facets.cc (__verify_grouping(const char*, size_t, const string&)): Also check that the value != CHAR_MAX. * include/bits/locale_facets.tcc (__numpunct_cache<>:: _M_cache(const locale&), __add_grouping(_CharT*, _CharT, const char*, size_t, const _CharT*, const _CharT*)): Likewise. * include/bits/locale_facets_nonio.tcc (__moneypunct_cache<>:: _M_cache(const locale&)): Likewise. * testsuite/22_locale/money_put/put/wchar_t/39168.cc: New. * testsuite/22_locale/money_put/put/char/39168.cc: Likewise. * testsuite/22_locale/money_get/get/wchar_t/39168.cc: Likewise. * testsuite/22_locale/money_get/get/char/39168.cc: Likewise. * testsuite/22_locale/num_get/get/wchar_t/39168.cc: Likewise. * testsuite/22_locale/num_get/get/char/39168.cc: Likewise. From-SVN: r144190
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog17
-rw-r--r--libstdc++-v3/include/bits/locale_facets.tcc7
-rw-r--r--libstdc++-v3/include/bits/locale_facets_nonio.tcc6
-rw-r--r--libstdc++-v3/src/locale_facets.cc5
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get/get/char/39168.cc57
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/39168.cc57
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_put/put/char/39168.cc51
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_put/put/wchar_t/39168.cc51
-rw-r--r--libstdc++-v3/testsuite/22_locale/num_get/get/char/39168.cc57
-rw-r--r--libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39168.cc57
10 files changed, 359 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c8d9d41..96c7905 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,20 @@
+2009-02-15 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR libstdc++/39168
+ * src/locale_facets.cc (__verify_grouping(const char*, size_t,
+ const string&)): Also check that the value != CHAR_MAX.
+ * include/bits/locale_facets.tcc (__numpunct_cache<>::
+ _M_cache(const locale&), __add_grouping(_CharT*, _CharT,
+ const char*, size_t, const _CharT*, const _CharT*)): Likewise.
+ * include/bits/locale_facets_nonio.tcc (__moneypunct_cache<>::
+ _M_cache(const locale&)): Likewise.
+ * testsuite/22_locale/money_put/put/wchar_t/39168.cc: New.
+ * testsuite/22_locale/money_put/put/char/39168.cc: Likewise.
+ * testsuite/22_locale/money_get/get/wchar_t/39168.cc: Likewise.
+ * testsuite/22_locale/money_get/get/char/39168.cc: Likewise.
+ * testsuite/22_locale/num_get/get/wchar_t/39168.cc: Likewise.
+ * testsuite/22_locale/num_get/get/char/39168.cc: Likewise.
+
2009-02-13 Chris Fairles <cfairles@gcc.gnu.org>
Benjamin Kosnik <bkoz@redhat.com>
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 779b4d5..93bc6d4 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -91,7 +91,9 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__np.grouping().copy(__grouping, _M_grouping_size);
_M_grouping = __grouping;
_M_use_grouping = (_M_grouping_size
- && static_cast<signed char>(__np.grouping()[0]) > 0);
+ && static_cast<signed char>(_M_grouping[0]) > 0
+ && (_M_grouping[0]
+ != __gnu_cxx::__numeric_traits<char>::__max));
_M_truename_size = __np.truename().size();
_CharT* __truename = new _CharT[_M_truename_size];
@@ -1232,7 +1234,8 @@ _GLIBCXX_END_LDBL_NAMESPACE
size_t __ctr = 0;
while (__last - __first > __gbeg[__idx]
- && static_cast<signed char>(__gbeg[__idx]) > 0)
+ && static_cast<signed char>(__gbeg[__idx]) > 0
+ && __gbeg[__idx] != __gnu_cxx::__numeric_traits<char>::__max)
{
__last -= __gbeg[__idx];
__idx < __gsize - 1 ? ++__idx : ++__ctr;
diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
index 9cc1b91..f32ad7f 100644
--- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
+++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
@@ -81,8 +81,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__mp.grouping().copy(__grouping, _M_grouping_size);
_M_grouping = __grouping;
_M_use_grouping = (_M_grouping_size
- && static_cast<signed char>(__mp.grouping()[0]) > 0);
-
+ && static_cast<signed char>(_M_grouping[0]) > 0
+ && (_M_grouping[0]
+ != __gnu_cxx::__numeric_traits<char>::__max));
+
_M_decimal_point = __mp.decimal_point();
_M_thousands_sep = __mp.thousands_sep();
_M_frac_digits = __mp.frac_digits();
diff --git a/libstdc++-v3/src/locale_facets.cc b/libstdc++-v3/src/locale_facets.cc
index 89c7e49..d62fb04 100644
--- a/libstdc++-v3/src/locale_facets.cc
+++ b/libstdc++-v3/src/locale_facets.cc
@@ -1,5 +1,5 @@
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007
+// 2006, 2007, 2008, 2009
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -110,7 +110,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// ... but the first parsed grouping can be <= numpunct
// grouping (only do the check if the numpunct char is > 0
// because <= 0 means any size is ok).
- if (static_cast<signed char>(__grouping[__min]) > 0)
+ if (static_cast<signed char>(__grouping[__min]) > 0
+ && __grouping[__min] != __gnu_cxx::__numeric_traits<char>::__max)
__test &= __grouping_tmp[0] <= __grouping[__min];
return __test;
}
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/39168.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/39168.cc
new file mode 100644
index 0000000..45cc692
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/39168.cc
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 22.2.6.1.1 money_get members
+
+#include <sstream>
+#include <locale>
+#include <climits>
+#include <testsuite_hooks.h>
+
+class my_moneypunct: public std::moneypunct<char>
+{
+protected:
+ std::string do_grouping() const { return std::string(1, CHAR_MAX); }
+};
+
+// libstdc++/39168
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef istreambuf_iterator<char> iterator_type;
+
+ istringstream iss;
+ iss.imbue(locale(iss.getloc(), new my_moneypunct));
+ const money_get<char>& mg = use_facet<money_get<char> >(iss.getloc());
+
+ string digits;
+ ios_base::iostate err = ios_base::goodbit;
+
+ iss.str("123,456");
+ iterator_type end = mg.get(iss.rdbuf(), 0, false, iss, err, digits);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( digits == "123" );
+ VERIFY( *end == ',' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/39168.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/39168.cc
new file mode 100644
index 0000000..44dd961
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/39168.cc
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 22.2.6.1.1 money_get members
+
+#include <sstream>
+#include <locale>
+#include <climits>
+#include <testsuite_hooks.h>
+
+class my_moneypunct: public std::moneypunct<wchar_t>
+{
+protected:
+ std::string do_grouping() const { return std::string(1, CHAR_MAX); }
+};
+
+// libstdc++/39168
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef istreambuf_iterator<wchar_t> iterator_type;
+
+ wistringstream iss;
+ iss.imbue(locale(iss.getloc(), new my_moneypunct));
+ const money_get<wchar_t>& mg = use_facet<money_get<wchar_t> >(iss.getloc());
+
+ wstring digits;
+ ios_base::iostate err = ios_base::goodbit;
+
+ iss.str(L"123,456");
+ iterator_type end = mg.get(iss.rdbuf(), 0, false, iss, err, digits);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( digits == L"123" );
+ VERIFY( *end == L',' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/money_put/put/char/39168.cc b/libstdc++-v3/testsuite/22_locale/money_put/put/char/39168.cc
new file mode 100644
index 0000000..1896933
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/money_put/put/char/39168.cc
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 22.2.6.2.1 money_put members
+
+#include <sstream>
+#include <locale>
+#include <climits>
+#include <testsuite_hooks.h>
+
+class my_moneypunct: public std::moneypunct<char>
+{
+protected:
+ std::string do_grouping() const { return std::string(1, CHAR_MAX); }
+};
+
+// libstdc++/39168
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ ostringstream oss;
+ oss.imbue(locale(oss.getloc(), new my_moneypunct));
+ const money_put<char>& mp = use_facet<money_put<char> >(oss.getloc());
+
+ string digits(300, '1');
+ mp.put(oss.rdbuf(), false, oss, ' ', digits);
+ VERIFY( oss.str() == digits );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/money_put/put/wchar_t/39168.cc b/libstdc++-v3/testsuite/22_locale/money_put/put/wchar_t/39168.cc
new file mode 100644
index 0000000..c1e195b
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/money_put/put/wchar_t/39168.cc
@@ -0,0 +1,51 @@
+// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 22.2.6.2.1 money_put members
+
+#include <sstream>
+#include <locale>
+#include <climits>
+#include <testsuite_hooks.h>
+
+class my_moneypunct: public std::moneypunct<wchar_t>
+{
+protected:
+ std::string do_grouping() const { return std::string(1, CHAR_MAX); }
+};
+
+// libstdc++/39168
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ wostringstream oss;
+ oss.imbue(locale(oss.getloc(), new my_moneypunct));
+ const money_put<wchar_t>& mp = use_facet<money_put<wchar_t> >(oss.getloc());
+
+ wstring digits(300, L'1');
+ mp.put(oss.rdbuf(), false, oss, ' ', digits);
+ VERIFY( oss.str() == digits );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/char/39168.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/char/39168.cc
new file mode 100644
index 0000000..9f83e1a
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/num_get/get/char/39168.cc
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 22.2.2.1.1 num_get members
+
+#include <sstream>
+#include <locale>
+#include <climits>
+#include <testsuite_hooks.h>
+
+class my_numpunct: public std::numpunct<char>
+{
+protected:
+ std::string do_grouping() const { return std::string(1, CHAR_MAX); }
+};
+
+// libstdc++/39168
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef istreambuf_iterator<char> iterator_type;
+
+ istringstream iss;
+ iss.imbue(locale(iss.getloc(), new my_numpunct));
+ const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
+
+ long double l = -1;
+ ios_base::iostate err = ios_base::goodbit;
+
+ iss.str("123,456");
+ iterator_type end = ng.get(iss.rdbuf(), 0, iss, err, l);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( l == 123 );
+ VERIFY( *end == ',' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39168.cc b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39168.cc
new file mode 100644
index 0000000..aa1bbf2
--- /dev/null
+++ b/libstdc++-v3/testsuite/22_locale/num_get/get/wchar_t/39168.cc
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 22.2.2.1.1 num_get members
+
+#include <sstream>
+#include <locale>
+#include <climits>
+#include <testsuite_hooks.h>
+
+class my_numpunct: public std::numpunct<wchar_t>
+{
+protected:
+ std::string do_grouping() const { return std::string(1, CHAR_MAX); }
+};
+
+// libstdc++/39168
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef istreambuf_iterator<wchar_t> iterator_type;
+
+ wistringstream iss;
+ iss.imbue(locale(iss.getloc(), new my_numpunct));
+ const num_get<wchar_t>& ng = use_facet<num_get<wchar_t> >(iss.getloc());
+
+ long double l = -1;
+ ios_base::iostate err = ios_base::goodbit;
+
+ iss.str(L"123,456");
+ iterator_type end = ng.get(iss.rdbuf(), 0, iss, err, l);
+ VERIFY( err == ios_base::goodbit );
+ VERIFY( l == 123 );
+ VERIFY( *end == L',' );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}