Skip to content
Snippets Groups Projects
Commit 8833255e authored by Wouter van Oortmerssen's avatar Wouter van Oortmerssen
Browse files

Merge pull request #227 from evanw/master

Round up allocation size to avoid misalignment (issue #226)
parents 185b9f97 47aab782
No related branches found
No related tags found
No related merge requests found
......@@ -416,7 +416,10 @@ class vector_downward {
uint8_t *make_space(size_t len) {
if (len > static_cast<size_t>(cur_ - buf_)) {
auto old_size = size();
auto largest_align = AlignOf<largest_scalar_t>();
reserved_ += std::max(len, growth_policy(reserved_));
// Round up to avoid undefined behavior from unaligned loads and stores.
reserved_ = (reserved_ + (largest_align - 1)) & ~(largest_align - 1);
auto new_buf = allocator_.allocate(reserved_);
auto new_cur = new_buf + reserved_ - old_size;
memcpy(new_cur, cur_, old_size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment