Buffer: add explicit/defensive coding checks.

This commit is contained in:
Kyle Isom 2023-10-19 21:00:35 -07:00
parent 6dab443789
commit eaea8c2ab0
1 changed files with 8 additions and 0 deletions

View File

@ -124,7 +124,15 @@ Buffer::Append(const uint8_t *data, const size_t datalen)
resized = true; resized = true;
} }
// If newCap is > 0, memory will be allocated for this->
// contents, and if contents was null, then Resize should force
// it to be allocated. Still, a little defensive coding never
// hurt.
assert(this->contents != nullptr); assert(this->contents != nullptr);
if (this->contents == nullptr) {
return false;
}
memcpy(this->contents + this->length, data, datalen); memcpy(this->contents + this->length, data, datalen);
this->length += datalen; this->length += datalen;
return resized; return resized;