locale_facets.tcc (collate::do_transform): Rewrite to fix problems with long transformed strings.

2002-03-11  Paolo Carlini  <pcarlini@unitus.it>

        * include/bits/locale_facets.tcc (collate::do_transform):
        Rewrite to fix problems with long transformed strings.

        * include/bits/locale_facets.tcc (time_put::do_put):
	Consider sizeof(char_type) in allocating the buffer.

From-SVN: r50617
This commit is contained in:
Paolo Carlini 2002-03-11 23:55:24 +01:00 committed by Paolo Carlini
parent 1875228965
commit c540620ceb
2 changed files with 19 additions and 8 deletions

View File

@ -1,3 +1,11 @@
2002-03-11 Paolo Carlini <pcarlini@unitus.it>
* include/bits/locale_facets.tcc (collate::do_transform):
Rewrite to fix problems with long transformed strings.
* include/bits/locale_facets.tcc (time_put::do_put):
Consider sizeof(char_type) in allocating the buffer.
2002-03-10 Anthony Green <green@redhat.com>
* configure.in: Support cross builds to mingw32 target.

View File

@ -1795,7 +1795,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(__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
@ -1854,16 +1855,18 @@ namespace std
collate<_CharT>::
do_transform(const _CharT* __lo, const _CharT* __hi) const
{
size_t __len = __hi - __lo;
_CharT* __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
size_t __len = (__hi - __lo) * 2;
// First try a buffer perhaps big enough.
_CharT* __c =
static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len));
size_t __res = _M_transform_helper(__c, __lo, __len);
// If the buffer was not large enough, try again with the correct size.
if (__res >= __len)
{
// Try to increment size of translated string.
size_t __len2 = __len * 2;
_CharT* __c2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len2));
__res = _M_transform_helper(__c2, __lo, __len);
// XXX Throw exception if still indeterminate?
_CharT* __c2 =
static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * (__res + 1)));
_M_transform_helper(__c2, __lo, __res + 1);
return string_type(__c2);
}
return string_type(__c);
}