https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119037

--- Comment #2 from Halalaluyafail3 <luigighiron at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> Most likely max_size in std::basic_string should be something like:
> 
> ```
>       ///  Returns the size() of the largest possible %string.
>       _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
>       size_type
>       max_size() const _GLIBCXX_NOEXCEPT
>       {
>         const size_t __diffmax
>           = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_CharT);
>         const size_t __allocmax =
> _Alloc_traits::max_size(_M_get_allocator());
>         return (std::max)(_S_local_capacity, (std::min)(__diffmax,
> __allocmax)) - 1;
>       }
> ```
> 
> That is taking into account the _S_local_capacity which does not need to
> call the allocator.

_S_local_capacity doesn't include the zero terminator (based off of the
definition _CharT _M_local_buf[_S_local_capacity + 1];) so there should be an
extra + 1. If that is changed, then this should fix the issues (aside from
max_size exceeding SIZE_MAX).

Reply via email to