locale_facets.tcc (collate::do_transform): Rewrite to fix problems with long transfor...
authorPaolo Carlini <pcarlini@unitus.it>
Sat, 9 Mar 2002 16:44:34 +0000 (17:44 +0100)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sat, 9 Mar 2002 16:44:34 +0000 (16:44 +0000)
2002-03-09  Paolo Carlini  <pcarlini@unitus.it>

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

From-SVN: r50500

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/locale_facets.tcc

index 7da26326f179c5f5c967e4ec35989cbaacd3e8ef..73551673226dedf89436c9dd96887e4c4cf94b62 100644 (file)
@@ -1,3 +1,8 @@
+2002-03-09  Paolo Carlini  <pcarlini@unitus.it>
+
+       * include/bits/locale_facets.tcc (collate::do_transform):
+       Rewrite to fix problems with long transformed strings.
+
 2002-03-08  Benjamin Kosnik  <bkoz@redhat.com>
 
        * c_locale_generic.cc: Move to...
index 3c8fea13024ca501b15a34b108f29143091580a3..90bb221c56ccebd56981ee9a7b9716e4bd0dfa2f 100644 (file)
@@ -1854,16 +1854,17 @@ namespace std
     collate<_CharT>::
     do_transform(const _CharT* __lo, const _CharT* __hi) const
     {
-      size_t __len = __hi - __lo;
+      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)));
+         size_t __res2 = _M_transform_helper(__c2, __lo, __res + 1);
+         return string_type(__c2);
        }
       return string_type(__c);
     }