Tweak reserve

It clamps to size() + 1, not just size(), i.e. we reserve the null byte.
We also check the exact requested capacity against the sso_max before we
do the (??) alignment (??) stuff.
This commit is contained in:
Jōshin 2024-06-06 16:46:59 -07:00
parent 731bdf7a06
commit 2d55834eaf
No known key found for this signature in database

View file

@ -89,13 +89,13 @@ string::reserve(size_t c2) noexcept
{
char* p2;
size_t n = size();
if (c2 < n)
c2 = n;
if (c2 < n + 1)
c2 = n + 1;
if (c2 <= __::string_size)
return;
if (ckd_add(&c2, c2, 15))
__builtin_trap();
c2 &= -16;
if (c2 <= __::sso_max)
return;
if (!isbig()) {
if (!(p2 = (char*)malloc(c2)))
__builtin_trap();