Commit 7d7d796c authored by Andrew Noyes's avatar Andrew Noyes Committed by Wouter van Oortmerssen

Fix undefined behavior. Closes #5422 (#5423)

* Fix undefined behavior. Closes #5422

* Move check into callers of make_space
parent 550b3869
...@@ -880,7 +880,7 @@ class vector_downward { ...@@ -880,7 +880,7 @@ class vector_downward {
uint8_t *data_at(size_t offset) const { return buf_ + reserved_ - offset; } uint8_t *data_at(size_t offset) const { return buf_ + reserved_ - offset; }
void push(const uint8_t *bytes, size_t num) { void push(const uint8_t *bytes, size_t num) {
memcpy(make_space(num), bytes, num); if (num > 0) { memcpy(make_space(num), bytes, num); }
} }
// Specialized version of push() that avoids memcpy call for small data. // Specialized version of push() that avoids memcpy call for small data.
...@@ -903,6 +903,7 @@ class vector_downward { ...@@ -903,6 +903,7 @@ class vector_downward {
} }
// Version for when we know the size is larger. // Version for when we know the size is larger.
// Precondition: zero_pad_bytes > 0
void fill_big(size_t zero_pad_bytes) { void fill_big(size_t zero_pad_bytes) {
memset(make_space(zero_pad_bytes), 0, zero_pad_bytes); memset(make_space(zero_pad_bytes), 0, zero_pad_bytes);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment