Merge pull request #105278 from Ivorforce/reserve-smoke-test

Smoke test: Log an error if `reserve()` is called with fewer elements than `size()`
This commit is contained in:
Thaddeus Crews 2025-04-23 12:01:28 -05:00
commit 931820d33c
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
7 changed files with 16 additions and 13 deletions

View file

@ -117,7 +117,8 @@ StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::append(const c
template <int SHORT_BUFFER_SIZE>
StringBuffer<SHORT_BUFFER_SIZE> &StringBuffer<SHORT_BUFFER_SIZE>::reserve(int p_size) {
if (p_size < SHORT_BUFFER_SIZE || p_size < buffer.size() || !p_size) {
ERR_FAIL_COND_V_MSG(p_size < length(), *this, "reserve() called with a capacity smaller than the current size. This is likely a mistake.");
if (p_size <= SHORT_BUFFER_SIZE || p_size <= buffer.size()) {
return *this;
}