Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: mojo/public/cpp/bindings/lib/scratch_buffer.cc

Issue 265403003: Make sure that ScratchBuffer::Allocate() always return 8-byte aligned address. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/buffer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/lib/scratch_buffer.cc
diff --git a/mojo/public/cpp/bindings/lib/scratch_buffer.cc b/mojo/public/cpp/bindings/lib/scratch_buffer.cc
index 9d23dcb13bba25b7b2dde5d1d5d5fc4f56847ca7..dee048f3a1ac3078fe0f564207e9d68bfe7b9d14 100644
--- a/mojo/public/cpp/bindings/lib/scratch_buffer.cc
+++ b/mojo/public/cpp/bindings/lib/scratch_buffer.cc
@@ -80,11 +80,12 @@ bool ScratchBuffer::AddOverflowSegment(size_t delta) {
return false;
// Ensure segment buffer is aligned.
- size_t segment_size = internal::Align(sizeof(Segment)) + delta;
- Segment* segment = static_cast<Segment*>(malloc(segment_size));
+ size_t padded_segment_size = internal::Align(sizeof(Segment));
+ Segment* segment = static_cast<Segment*>(
+ malloc(padded_segment_size + delta));
if (segment) {
segment->next = overflow_;
- segment->cursor = reinterpret_cast<char*>(segment + 1);
+ segment->cursor = reinterpret_cast<char*>(segment) + padded_segment_size;
darin (slow to review) 2014/05/05 22:55:52 good catch!
segment->end = segment->cursor + delta;
overflow_ = segment;
return true;
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698