summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/locale_conv.h
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/include/bits/locale_conv.h')
-rw-r--r--libstdc++-v3/include/bits/locale_conv.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/libstdc++-v3/include/bits/locale_conv.h b/libstdc++-v3/include/bits/locale_conv.h
index c8a44f42421..b53754d1541 100644
--- a/libstdc++-v3/include/bits/locale_conv.h
+++ b/libstdc++-v3/include/bits/locale_conv.h
@@ -198,18 +198,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
auto __outstr = __err ? _OutStr(__err->get_allocator()) : _OutStr();
size_t __outchars = 0;
auto __next = __first;
+ const auto __maxlen = _M_cvt->max_length();
codecvt_base::result __result;
do
{
- __outstr.resize(__outstr.size() + (__last - __next));
+ __outstr.resize(__outstr.size() + (__last - __next) + __maxlen);
auto __outnext = &__outstr.front() + __outchars;
auto const __outlast = &__outstr.back() + 1;
__result = ((*_M_cvt).*__memfn)(_M_state, __next, __last, __next,
__outnext, __outlast, __outnext);
__outchars = __outnext - &__outstr.front();
}
- while (__result == codecvt_base::partial && __next != __last);
+ while (__result == codecvt_base::partial && __next != __last
+ && (__outstr.size() - __outchars) < __maxlen);
__outstr.resize(__outchars);
_M_count = __next - __first;
@@ -428,7 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _M_put(__next, __pending);
if (!_M_put(__outbuf, __outnext - __outbuf))
- return false;
+ return false;
}
while (__next != __last && __next != __start);