[libcxx-commits] [libcxx] [libc++] Fix basic_string not allowing max_size() elements to be stored (PR #125423)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 20 05:28:09 PST 2025
================
@@ -1302,10 +1302,10 @@ public:
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT {
size_type __m = __alloc_traits::max_size(__alloc_);
if (__m <= std::numeric_limits<size_type>::max() / 2) {
- return __m - __alignment;
+ return ((__m - __alignment) & ~size_type(__endian_factor - 1)) - 1;
----------------
philnik777 wrote:
This has changed in the latest revision. Previously the capacity would be one too low when the `max_size()` is even with `__endian_factor == 2`. In that mode we require the capacity (including the null terminator) to always be even, which is violated with `max_size()` (which returns the size _without_ the null terminator) returning an even number.
https://github.com/llvm/llvm-project/pull/125423
More information about the libcxx-commits
mailing list