This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[v3] libstdc++/39168
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sun, 15 Feb 2009 17:49:08 +0100
- Subject: [v3] libstdc++/39168
Hi,
tested x86_64-linux, committed to mainline.
Paolo.
////////////////////
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.
Index: src/locale_facets.cc
===================================================================
--- src/locale_facets.cc (revision 144188)
+++ src/locale_facets.cc (working copy)
@@ -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 @@
// ... 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;
}
Index: include/bits/locale_facets.tcc
===================================================================
--- include/bits/locale_facets.tcc (revision 144188)
+++ include/bits/locale_facets.tcc (working copy)
@@ -91,7 +91,9 @@
__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 @@
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;
Index: include/bits/locale_facets_nonio.tcc
===================================================================
--- include/bits/locale_facets_nonio.tcc (revision 144188)
+++ include/bits/locale_facets_nonio.tcc (working copy)
@@ -81,8 +81,10 @@
__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();
Index: testsuite/22_locale/money_put/put/wchar_t/39168.cc
===================================================================
--- testsuite/22_locale/money_put/put/wchar_t/39168.cc (revision 0)
+++ testsuite/22_locale/money_put/put/wchar_t/39168.cc (revision 0)
@@ -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;
+}
Index: testsuite/22_locale/money_put/put/char/39168.cc
===================================================================
--- testsuite/22_locale/money_put/put/char/39168.cc (revision 0)
+++ testsuite/22_locale/money_put/put/char/39168.cc (revision 0)
@@ -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;
+}
Index: testsuite/22_locale/money_get/get/wchar_t/39168.cc
===================================================================
--- testsuite/22_locale/money_get/get/wchar_t/39168.cc (revision 0)
+++ testsuite/22_locale/money_get/get/wchar_t/39168.cc (revision 0)
@@ -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;
+}
Index: testsuite/22_locale/money_get/get/char/39168.cc
===================================================================
--- testsuite/22_locale/money_get/get/char/39168.cc (revision 0)
+++ testsuite/22_locale/money_get/get/char/39168.cc (revision 0)
@@ -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;
+}
Index: testsuite/22_locale/num_get/get/wchar_t/39168.cc
===================================================================
--- testsuite/22_locale/num_get/get/wchar_t/39168.cc (revision 0)
+++ testsuite/22_locale/num_get/get/wchar_t/39168.cc (revision 0)
@@ -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;
+}
Index: testsuite/22_locale/num_get/get/char/39168.cc
===================================================================
--- testsuite/22_locale/num_get/get/char/39168.cc (revision 0)
+++ testsuite/22_locale/num_get/get/char/39168.cc (revision 0)
@@ -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;
+}