Buffer: add explicit/defensive coding checks.
This commit is contained in:
parent
6dab443789
commit
eaea8c2ab0
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue