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

Side by Side Diff: mojo/public/cpp/bindings/lib/fixed_buffer.cc

Issue 399313007: Mojo: Convert assert()s under mojo/public/cpp/bindings/... to MOJO_DCHECK()s. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
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/fixed_buffer.h" 5 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
6 6
7 #include <assert.h>
8 #include <stdlib.h> 7 #include <stdlib.h>
9 #include <string.h>
10 8
11 #include <algorithm> 9 #include <algorithm>
12 10
13 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h" 11 #include "mojo/public/cpp/bindings/lib/bindings_serialization.h"
12 #include "mojo/public/cpp/environment/logging.h"
14 13
15 namespace mojo { 14 namespace mojo {
16 namespace internal { 15 namespace internal {
17 16
18 FixedBuffer::FixedBuffer(size_t size) 17 FixedBuffer::FixedBuffer(size_t size)
19 : ptr_(NULL), 18 : ptr_(NULL),
20 cursor_(0), 19 cursor_(0),
21 size_(internal::Align(size)) { 20 size_(internal::Align(size)) {
22 // calloc() required to zero memory and thus avoid info leaks. 21 // calloc() required to zero memory and thus avoid info leaks.
23 ptr_ = static_cast<char*>(calloc(size_, 1)); 22 ptr_ = static_cast<char*>(calloc(size_, 1));
24 } 23 }
25 24
26 FixedBuffer::~FixedBuffer() { 25 FixedBuffer::~FixedBuffer() {
27 free(ptr_); 26 free(ptr_);
28 } 27 }
29 28
30 void* FixedBuffer::Allocate(size_t delta) { 29 void* FixedBuffer::Allocate(size_t delta) {
31 delta = internal::Align(delta); 30 delta = internal::Align(delta);
32 31
33 if (delta == 0 || delta > size_ - cursor_) { 32 if (delta == 0 || delta > size_ - cursor_) {
34 assert(false); 33 MOJO_DCHECK(false) << "Not reached";
35 return NULL; 34 return NULL;
36 } 35 }
37 36
38 char* result = ptr_ + cursor_; 37 char* result = ptr_ + cursor_;
39 cursor_ += delta; 38 cursor_ += delta;
40 39
41 return result; 40 return result;
42 } 41 }
43 42
44 void* FixedBuffer::Leak() { 43 void* FixedBuffer::Leak() {
45 char* ptr = ptr_; 44 char* ptr = ptr_;
46 ptr_ = NULL; 45 ptr_ = NULL;
47 cursor_ = 0; 46 cursor_ = 0;
48 size_ = 0; 47 size_ = 0;
49 return ptr; 48 return ptr;
50 } 49 }
51 50
52 } // namespace internal 51 } // namespace internal
53 } // namespace mojo 52 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698