mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-30 07:14:09 +08:00
re PR libstdc++/12791 (_M_extract_num returns a wrong __beg in case of error)
2003-12-03 Paolo Carlini <pcarlini@suse.de> PR libstdc++/12791 * include/bits/locale_facets.tcc (time_get::_M_extract_num): Rewrite, stop the parsing as soon as a digit cannot possibly lead to a final number within the bounds; otherwise, simplify, avoiding __ctype.is() and atoi(). * testsuite/22_locale/time_get/get_date/char/12791.cc: New. * testsuite/22_locale/time_get/get_date/wchar_t/12791.cc: New. * include/bits/locale_facets.tcc (time_get::_M_extract_via_format): Minor tweak: a 4-digit integer cannot be bigger than 9999. * testsuite/22_locale/time_get/get_date/wchar_t/1.cc: Use type-correct wchar_t string literals. * testsuite/22_locale/time_get/get_monthname/wchar_t/1.cc: Ditto. * testsuite/22_locale/time_get/get_time/wchar_t/1.cc: Ditto. * testsuite/22_locale/time_get/get_weekday/wchar_t/1.cc: Ditto. * testsuite/22_locale/time_get/get_year/wchar_t/1.cc: Ditto. From-SVN: r74220
This commit is contained in:
parent
c6a25d3a3d
commit
3259561c4c
@ -1,3 +1,23 @@
|
||||
2003-12-03 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
PR libstdc++/12791
|
||||
* include/bits/locale_facets.tcc (time_get::_M_extract_num):
|
||||
Rewrite, stop the parsing as soon as a digit cannot possibly
|
||||
lead to a final number within the bounds; otherwise, simplify,
|
||||
avoiding __ctype.is() and atoi().
|
||||
* testsuite/22_locale/time_get/get_date/char/12791.cc: New.
|
||||
* testsuite/22_locale/time_get/get_date/wchar_t/12791.cc: New.
|
||||
|
||||
* include/bits/locale_facets.tcc (time_get::_M_extract_via_format):
|
||||
Minor tweak: a 4-digit integer cannot be bigger than 9999.
|
||||
|
||||
* testsuite/22_locale/time_get/get_date/wchar_t/1.cc: Use
|
||||
type-correct wchar_t string literals.
|
||||
* testsuite/22_locale/time_get/get_monthname/wchar_t/1.cc: Ditto.
|
||||
* testsuite/22_locale/time_get/get_time/wchar_t/1.cc: Ditto.
|
||||
* testsuite/22_locale/time_get/get_weekday/wchar_t/1.cc: Ditto.
|
||||
* testsuite/22_locale/time_get/get_year/wchar_t/1.cc: Ditto.
|
||||
|
||||
2003-12-02 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/bits/locale_facets.tcc (time_get::do_get_year):
|
||||
|
@ -1679,8 +1679,7 @@ namespace std
|
||||
break;
|
||||
case 'Y':
|
||||
// Year [1900). [tm_year]
|
||||
_M_extract_num(__beg, __end, __mem, 0,
|
||||
numeric_limits<int>::max(), 4,
|
||||
_M_extract_num(__beg, __end, __mem, 0, 9999, 4,
|
||||
__ctype, __err);
|
||||
if (!__err)
|
||||
__tm->tm_year = __mem - 1900;
|
||||
@ -1732,23 +1731,29 @@ namespace std
|
||||
const ctype<_CharT>& __ctype,
|
||||
ios_base::iostate& __err) const
|
||||
{
|
||||
// As-is works for __len = 1, 2, 4, the values actually used.
|
||||
int __mult = __len == 2 ? 10 : (__len == 4 ? 1000 : 1);
|
||||
|
||||
++__min;
|
||||
size_t __i = 0;
|
||||
string __digits;
|
||||
bool __testvalid = true;
|
||||
for (; __beg != __end && __i < __len
|
||||
&& __ctype.is(ctype_base::digit, *__beg); ++__beg, ++__i)
|
||||
__digits += __ctype.narrow(*__beg, 0);
|
||||
if (__i == __len)
|
||||
int __value = 0;
|
||||
for (; __beg != __end && __i < __len; ++__beg, ++__i)
|
||||
{
|
||||
const int __value = std::atoi(__digits.c_str());
|
||||
if (__min <= __value && __value <= __max)
|
||||
__member = __value;
|
||||
const char __c = __ctype.narrow(*__beg, '*');
|
||||
if (__c >= '0' && __c <= '9')
|
||||
{
|
||||
__value = __value * 10 + (__c - '0');
|
||||
const int __valuec = __value * __mult;
|
||||
if (__valuec > __max || __valuec + __mult < __min)
|
||||
break;
|
||||
__mult /= 10;
|
||||
}
|
||||
else
|
||||
__testvalid = false;
|
||||
break;
|
||||
}
|
||||
if (__i == __len)
|
||||
__member = __value;
|
||||
else
|
||||
__testvalid = false;
|
||||
if (!__testvalid)
|
||||
__err |= ios_base::failbit;
|
||||
}
|
||||
|
||||
@ -2031,7 +2036,8 @@ namespace std
|
||||
// NB: This size is arbitrary. Should this be a data member,
|
||||
// initialized at construction?
|
||||
const size_t __maxlen = 64;
|
||||
char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type) * __maxlen));
|
||||
char_type* __res = static_cast<char_type*>(__builtin_alloca(sizeof(char_type)
|
||||
* __maxlen));
|
||||
|
||||
// NB: In IEE 1003.1-200x, and perhaps other locale models, it
|
||||
// is possible that the format character will be longer than one
|
||||
|
@ -0,0 +1,65 @@
|
||||
// 2003-12-03 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// 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.
|
||||
|
||||
// 22.2.5.1.1 time_get members
|
||||
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
// libstdc++/12791
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
typedef istreambuf_iterator<char> iterator_type;
|
||||
|
||||
// create an ostream-derived object, cache the time_get facet
|
||||
iterator_type end;
|
||||
|
||||
istringstream iss;
|
||||
const time_get<char>& tim_get = use_facet<time_get<char> >(iss.getloc());
|
||||
|
||||
const ios_base::iostate good = ios_base::goodbit;
|
||||
ios_base::iostate errorstate = good;
|
||||
|
||||
iss.str("60/04/71");
|
||||
iterator_type is_it01(iss);
|
||||
tm time01;
|
||||
errorstate = good;
|
||||
tim_get.get_date(is_it01, end, iss, errorstate, &time01);
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
VERIFY( *is_it01 == '6' );
|
||||
|
||||
iss.str("04/38/71");
|
||||
iterator_type is_it02(iss);
|
||||
tm time02;
|
||||
errorstate = good;
|
||||
tim_get.get_date(is_it02, end, iss, errorstate, &time02);
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
VERIFY( *is_it02 == '8' );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -80,7 +80,7 @@ void test01()
|
||||
VERIFY( time02.tm_mon == time_bday.tm_mon );
|
||||
VERIFY( time02.tm_mday == time_bday.tm_mday );
|
||||
VERIFY( errorstate == good );
|
||||
VERIFY( *is_it02 == ' ');
|
||||
VERIFY( *is_it02 == L' ' );
|
||||
|
||||
iss.str(L"04/04d/71 ");
|
||||
iterator_type is_it03(iss);
|
||||
@ -92,7 +92,7 @@ void test01()
|
||||
VERIFY( time03.tm_mon == time_bday.tm_mon );
|
||||
VERIFY( time03.tm_mday == time_bday.tm_mday );
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
VERIFY( *is_it03 == 'd');
|
||||
VERIFY( *is_it03 == L'd' );
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@ -0,0 +1,65 @@
|
||||
// 2003-12-03 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
// 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.
|
||||
|
||||
// 22.2.5.1.1 time_get members
|
||||
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
// libstdc++/12791
|
||||
void test01()
|
||||
{
|
||||
using namespace std;
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
typedef istreambuf_iterator<wchar_t> iterator_type;
|
||||
|
||||
// create an ostream-derived object, cache the time_get facet
|
||||
iterator_type end;
|
||||
|
||||
wistringstream iss;
|
||||
const time_get<wchar_t>& tim_get = use_facet<time_get<wchar_t> >(iss.getloc());
|
||||
|
||||
const ios_base::iostate good = ios_base::goodbit;
|
||||
ios_base::iostate errorstate = good;
|
||||
|
||||
iss.str(L"60/04/71");
|
||||
iterator_type is_it01(iss);
|
||||
tm time01;
|
||||
errorstate = good;
|
||||
tim_get.get_date(is_it01, end, iss, errorstate, &time01);
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
VERIFY( *is_it01 == L'6' );
|
||||
|
||||
iss.str(L"04/38/71");
|
||||
iterator_type is_it02(iss);
|
||||
tm time02;
|
||||
errorstate = good;
|
||||
tim_get.get_date(is_it02, end, iss, errorstate, &time02);
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
VERIFY( *is_it02 == L'8' );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -81,7 +81,7 @@ void test01()
|
||||
tim_get.get_monthname(is_it03, end, iss, errorstate, &time03);
|
||||
VERIFY( time03.tm_mon == time_bday.tm_mon );
|
||||
VERIFY( errorstate == good );
|
||||
VERIFY( *is_it03 == ' ');
|
||||
VERIFY( *is_it03 == L' ' );
|
||||
|
||||
iss.str(L"Aar");
|
||||
iterator_type is_it04(iss);
|
||||
@ -90,7 +90,7 @@ void test01()
|
||||
errorstate = good;
|
||||
tim_get.get_monthname(is_it04, end, iss, errorstate, &time04);
|
||||
VERIFY( time04.tm_mon == 5 );
|
||||
VERIFY( *is_it04 == 'a');
|
||||
VERIFY( *is_it04 == L'a' );
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
|
||||
iss.str(L"December ");
|
||||
@ -100,7 +100,7 @@ void test01()
|
||||
tim_get.get_monthname(is_it05, end, iss, errorstate, &time05);
|
||||
VERIFY( time05.tm_mon == 11 );
|
||||
VERIFY( errorstate == good );
|
||||
VERIFY( *is_it05 == ' ');
|
||||
VERIFY( *is_it05 == L' ' );
|
||||
|
||||
iss.str(L"Decelember ");
|
||||
iterator_type is_it06(iss);
|
||||
@ -110,7 +110,7 @@ void test01()
|
||||
tim_get.get_monthname(is_it06, end, iss, errorstate, &time06);
|
||||
VERIFY( time06.tm_mon == 4 );
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
VERIFY( *is_it05 == 'l');
|
||||
VERIFY( *is_it05 == L'l' );
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@ -94,7 +94,7 @@ void test01()
|
||||
errorstate = good;
|
||||
tim_get.get_time(is_it04, end, iss, errorstate, &time04);
|
||||
VERIFY( time01.tm_hour == time_bday.tm_hour );
|
||||
VERIFY( *is_it04 == 'a');
|
||||
VERIFY( *is_it04 == L'a' );
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
|
||||
// inspection of named locales, de_DE
|
||||
|
@ -76,7 +76,7 @@ void test01()
|
||||
tim_get.get_year(is_it02, end, iss, errorstate, &time02);
|
||||
VERIFY( time02.tm_year == time_bday.tm_year );
|
||||
VERIFY( errorstate == good );
|
||||
VERIFY( *is_it02 == ' ');
|
||||
VERIFY( *is_it02 == L' ' );
|
||||
|
||||
iss.str(L"197d1 ");
|
||||
iterator_type is_it03(iss);
|
||||
@ -86,7 +86,7 @@ void test01()
|
||||
tim_get.get_year(is_it03, end, iss, errorstate, &time03);
|
||||
VERIFY( time03.tm_year == 3 );
|
||||
VERIFY( errorstate == ios_base::failbit );
|
||||
VERIFY( *is_it03 == 'd');
|
||||
VERIFY( *is_it03 == L'd' );
|
||||
|
||||
iss.str(L"71d71");
|
||||
iterator_type is_it04(iss);
|
||||
@ -95,7 +95,7 @@ void test01()
|
||||
tim_get.get_year(is_it04, end, iss, errorstate, &time04);
|
||||
VERIFY( time04.tm_year == time_bday.tm_year );
|
||||
VERIFY( errorstate == good );
|
||||
VERIFY( *is_it03 == 'd');
|
||||
VERIFY( *is_it03 == L'd' );
|
||||
|
||||
iss.str(L"71");
|
||||
iterator_type is_it05(iss);
|
||||
|
Loading…
Reference in New Issue
Block a user