From 2d55834eaf12e0bab01e4c7140978638e77241ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Thu, 6 Jun 2024 16:46:59 -0700 Subject: [PATCH] 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. --- ctl/string.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctl/string.cc b/ctl/string.cc index 2c3811318..d7a692158 100644 --- a/ctl/string.cc +++ b/ctl/string.cc @@ -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();