OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef OTS_MEMORY_STREAM_H_ | 5 #ifndef OTS_MEMORY_STREAM_H_ |
6 #define OTS_MEMORY_STREAM_H_ | 6 #define OTS_MEMORY_STREAM_H_ |
7 | 7 |
8 #include <cstring> | 8 #include <cstring> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 if ((off_ + length > length_) || | 64 if ((off_ + length > length_) || |
65 (length > std::numeric_limits<size_t>::max() - off_)) { | 65 (length > std::numeric_limits<size_t>::max() - off_)) { |
66 if (length_ == limit_) | 66 if (length_ == limit_) |
67 return false; | 67 return false; |
68 size_t new_length = (length_ + 1) * 2; | 68 size_t new_length = (length_ + 1) * 2; |
69 if (new_length < length_) | 69 if (new_length < length_) |
70 return false; | 70 return false; |
71 if (new_length > limit_) | 71 if (new_length > limit_) |
72 new_length = limit_; | 72 new_length = limit_; |
73 uint8_t* new_buf = new uint8_t[new_length]; | 73 uint8_t* new_buf = new uint8_t[new_length]; |
74 memcpy(new_buf, ptr_, length_); | 74 std::memcpy(new_buf, ptr_, length_); |
75 length_ = new_length; | 75 length_ = new_length; |
76 delete[] static_cast<uint8_t*>(ptr_); | 76 delete[] static_cast<uint8_t*>(ptr_); |
77 ptr_ = new_buf; | 77 ptr_ = new_buf; |
78 return WriteRaw(data, length); | 78 return WriteRaw(data, length); |
79 } | 79 } |
80 std::memcpy(static_cast<char*>(ptr_) + off_, data, length); | 80 std::memcpy(static_cast<char*>(ptr_) + off_, data, length); |
81 off_ += length; | 81 off_ += length; |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
(...skipping 11 matching lines...) Expand all Loading... |
96 private: | 96 private: |
97 void* ptr_; | 97 void* ptr_; |
98 size_t length_; | 98 size_t length_; |
99 const size_t limit_; | 99 const size_t limit_; |
100 off_t off_; | 100 off_t off_; |
101 }; | 101 }; |
102 | 102 |
103 } // namespace ots | 103 } // namespace ots |
104 | 104 |
105 #endif // OTS_MEMORY_STREAM_H_ | 105 #endif // OTS_MEMORY_STREAM_H_ |
OLD | NEW |