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

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: fix on-stack allocation alignment. 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
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..c7f507be285e921b81f710510535c9624311ddce 100644
--- a/mojo/public/cpp/bindings/lib/scratch_buffer.cc
+++ b/mojo/public/cpp/bindings/lib/scratch_buffer.cc
@@ -25,7 +25,7 @@ namespace internal {
ScratchBuffer::ScratchBuffer()
: overflow_(NULL) {
fixed_.next = NULL;
- fixed_.cursor = fixed_data_;
+ fixed_.cursor = internal::AlignPointer(fixed_data_);
darin (slow to review) 2014/05/06 07:32:55 maybe we should align fixed_.end too? doesn't thi
darin (slow to review) 2014/05/06 07:35:29 nevermind. that would increase fixed_.end in some
yzshen1 2014/05/06 08:06:43 On 32-bit systems, it is possible that pointers ar
fixed_.end = fixed_data_ + kMinSegmentSize;
}
@@ -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;
segment->end = segment->cursor + delta;
overflow_ = segment;
return true;
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_serialization.cc ('k') | mojo/public/cpp/bindings/tests/buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698