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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/buffer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/cpp/bindings/lib/scratch_buffer.h" 5 #include "mojo/public/cpp/bindings/lib/scratch_buffer.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 bool ScratchBuffer::AddOverflowSegment(size_t delta) { 75 bool ScratchBuffer::AddOverflowSegment(size_t delta) {
76 if (delta < kMinSegmentSize) 76 if (delta < kMinSegmentSize)
77 delta = kMinSegmentSize; 77 delta = kMinSegmentSize;
78 78
79 if (delta > kMaxSegmentSize) 79 if (delta > kMaxSegmentSize)
80 return false; 80 return false;
81 81
82 // Ensure segment buffer is aligned. 82 // Ensure segment buffer is aligned.
83 size_t segment_size = internal::Align(sizeof(Segment)) + delta; 83 size_t padded_segment_size = internal::Align(sizeof(Segment));
84 Segment* segment = static_cast<Segment*>(malloc(segment_size)); 84 Segment* segment = static_cast<Segment*>(
85 malloc(padded_segment_size + delta));
85 if (segment) { 86 if (segment) {
86 segment->next = overflow_; 87 segment->next = overflow_;
87 segment->cursor = reinterpret_cast<char*>(segment + 1); 88 segment->cursor = reinterpret_cast<char*>(segment) + padded_segment_size;
darin (slow to review) 2014/05/05 22:55:52 good catch!
88 segment->end = segment->cursor + delta; 89 segment->end = segment->cursor + delta;
89 overflow_ = segment; 90 overflow_ = segment;
90 return true; 91 return true;
91 } 92 }
92 93
93 return false; 94 return false;
94 } 95 }
95 96
96 } // namespace internal 97 } // namespace internal
97 } // namespace mojo 98 } // namespace mojo
OLDNEW
« 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