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

Side by Side Diff: trunk/src/mojo/public/cpp/bindings/lib/scratch_buffer.cc

Issue 265823012: Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..." (Closed) Base URL: svn://svn.chromium.org/chrome/
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 | trunk/src/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 padded_segment_size = internal::Align(sizeof(Segment)); 83 size_t segment_size = internal::Align(sizeof(Segment)) + delta;
84 Segment* segment = static_cast<Segment*>( 84 Segment* segment = static_cast<Segment*>(malloc(segment_size));
85 malloc(padded_segment_size + delta));
86 if (segment) { 85 if (segment) {
87 segment->next = overflow_; 86 segment->next = overflow_;
88 segment->cursor = reinterpret_cast<char*>(segment) + padded_segment_size; 87 segment->cursor = reinterpret_cast<char*>(segment + 1);
89 segment->end = segment->cursor + delta; 88 segment->end = segment->cursor + delta;
90 overflow_ = segment; 89 overflow_ = segment;
91 return true; 90 return true;
92 } 91 }
93 92
94 return false; 93 return false;
95 } 94 }
96 95
97 } // namespace internal 96 } // namespace internal
98 } // namespace mojo 97 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | trunk/src/mojo/public/cpp/bindings/tests/buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698