From 1403221a88a74b53b39916ea722f9fca8497cf8e Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Thu, 25 Oct 2001 22:56:07 +0000 Subject: [PATCH] locale_facets.tcc (collate::do_transform): Fix. 2001-10-25 Benjamin Kosnik * include/bits/locale_facets.tcc (collate::do_transform): Fix. From-SVN: r46500 --- libstdc++-v3/ChangeLog | 4 ++++ libstdc++-v3/include/bits/locale_facets.tcc | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ce05b96f217..b64f5705499 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,7 @@ +2001-10-25 Benjamin Kosnik + + * include/bits/locale_facets.tcc (collate::do_transform): Fix. + 2001-10-25 Phil Edwards * docs/html/documentation.html: Fix typo. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 7072c0ba93f..e574db09ab2 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -1879,19 +1879,18 @@ namespace std collate<_CharT>:: do_transform(const _CharT* __lo, const _CharT* __hi) const { - string_type __orig(__lo, __hi); - string_type __trans(__orig.size(), char_type()); - size_t __res = _M_transform_helper(__trans.begin().base(), - __orig.c_str(), __trans.size()); - while (__res >= __trans.size()) + size_t __len = __hi - __lo; + _CharT* __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len)); + size_t __res = _M_transform_helper(__c, __lo, __len); + if (__res >= __len) { - // Increment size of translated string. - typename string_type::size_type __newsize = __trans.size() * 2; - __trans.resize(__newsize); - __res = _M_transform_helper(__trans.begin().base(), __orig.c_str(), - __trans.size()); + // 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? } - return __trans; + return string_type(__c); } template -- 2.30.2