OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkData.h" | 8 #include "SkData.h" |
9 #include "SkLazyPtr.h" | 9 #include "SkLazyPtr.h" |
10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 SkASSERT(length > 0); | 56 SkASSERT(length > 0); |
57 | 57 |
58 memcpy(buffer, this->bytes() + offset, length); | 58 memcpy(buffer, this->bytes() + offset, length); |
59 return length; | 59 return length; |
60 } | 60 } |
61 | 61 |
62 SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) { | 62 SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) { |
63 if (0 == length) { | 63 if (0 == length) { |
64 return SkData::NewEmpty(); | 64 return SkData::NewEmpty(); |
65 } | 65 } |
66 char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length); | 66 |
| 67 const size_t actualLength = length + sizeof(SkData); |
| 68 if (actualLength < length) { |
| 69 // we overflowed |
| 70 sk_throw(); |
| 71 } |
| 72 |
| 73 char* storage = (char*)sk_malloc_throw(actualLength); |
67 SkData* data = new (storage) SkData(length); | 74 SkData* data = new (storage) SkData(length); |
68 if (srcOrNull) { | 75 if (srcOrNull) { |
69 memcpy(data->writable_data(), srcOrNull, length); | 76 memcpy(data->writable_data(), srcOrNull, length); |
70 } | 77 } |
71 return data; | 78 return data; |
72 } | 79 } |
73 | 80 |
74 /////////////////////////////////////////////////////////////////////////////// | 81 /////////////////////////////////////////////////////////////////////////////// |
75 | 82 |
76 // As a template argument these must have external linkage. | 83 // As a template argument these must have external linkage. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 /////////////////////////////////////////////////////////////////////////////// | 190 /////////////////////////////////////////////////////////////////////////////// |
184 | 191 |
185 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { | 192 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { |
186 SkAutoDataUnref data(SkData::NewUninitialized(size)); | 193 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
187 if (stream->read(data->writable_data(), size) != size) { | 194 if (stream->read(data->writable_data(), size) != size) { |
188 return NULL; | 195 return NULL; |
189 } | 196 } |
190 return data.detach(); | 197 return data.detach(); |
191 } | 198 } |
192 | 199 |
OLD | NEW |