Buffer: add explicit/defensive coding checks.

This commit is contained in:
2023-10-19 21:00:35 -07:00
parent 6dab443789
commit eaea8c2ab0

View File

@@ -124,7 +124,15 @@ Buffer::Append(const uint8_t *data, const size_t datalen)
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);
if (this->contents == nullptr) {
return false;
}
memcpy(this->contents + this->length, data, datalen);
this->length += datalen;
return resized;