diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-08-15 14:52:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-15 14:52:43 +0200 |
commit | e72ccbe7d79e47235414909720097c648476eab5 (patch) | |
tree | 85350b6d30d7fb5e188f1ff77ea72e1db16ee40d | |
parent | 113b75e2bc29aa163f18732e2e1ebc8c5bd47987 (diff) | |
parent | 6d80ddb5bab65a016566004d25bdcc1c3525d317 (diff) |
Merge pull request #28053 from vespa-engine/balder/assert-that-you-got-memory
Assert that you actually got memory you allocated.
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/string.hpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/stllike/string.hpp b/vespalib/src/vespa/vespalib/stllike/string.hpp index e0144ab6f85..3438c6b641a 100644 --- a/vespalib/src/vespa/vespalib/stllike/string.hpp +++ b/vespalib/src/vespa/vespalib/stllike/string.hpp @@ -17,8 +17,10 @@ void small_string<StackSize>::_reserveBytes(size_type newBufferSize) noexcept { if (isAllocated()) { _buf = (char *) realloc(_buf, newBufferSize); + assert(_buf); } else { char *tmp = (char *) malloc(newBufferSize); + assert(tmp); memcpy(tmp, _stack, _sz); tmp[_sz] = '\0'; _buf = tmp; @@ -96,6 +98,7 @@ void small_string<StackSize>::init_slower(const void *s) noexcept { _bufferSize = _sz+1; _buf = (char *) malloc(_bufferSize); + assert(_buf); memcpy(_buf, s, _sz); _buf[_sz] = '\0'; } @@ -105,6 +108,7 @@ void small_string<StackSize>::appendAlloc(const void * s, size_type addSz) noexc { size_type newBufferSize = roundUp2inN(_sz+addSz+1); char * buf = (char *) malloc(newBufferSize); + assert(buf); memcpy(buf, buffer(), _sz); if (isAllocated()) { free(_buf); |