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

Side by Side Diff: include/core/SkTArray.h

Issue 1510683002: Add sk_careful_memcpy to catch undefined behavior in memcpy. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reed Created 5 years 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
« no previous file with comments | « gyp/common_conditions.gypi ('k') | include/core/SkTDArray.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef SkTArray_DEFINED 8 #ifndef SkTArray_DEFINED
9 #define SkTArray_DEFINED 9 #define SkTArray_DEFINED
10 10
11 #include "../private/SkTemplates.h" 11 #include "../private/SkTemplates.h"
12 #include "SkTypes.h" 12 #include "SkTypes.h"
13 13
14 #include <new> 14 #include <new>
15 15
16 template <typename T, bool MEM_COPY = false> class SkTArray; 16 template <typename T, bool MEM_COPY = false> class SkTArray;
17 17
18 namespace SkTArrayExt { 18 namespace SkTArrayExt {
19 19
20 template<typename T> 20 template<typename T>
21 inline void copy(SkTArray<T, true>* self, int dst, int src) { 21 inline void copy(SkTArray<T, true>* self, int dst, int src) {
22 memcpy(&self->fItemArray[dst], &self->fItemArray[src], sizeof(T)); 22 memcpy(&self->fItemArray[dst], &self->fItemArray[src], sizeof(T));
23 } 23 }
24 template<typename T> 24 template<typename T>
25 inline void copy(SkTArray<T, true>* self, const T* array) { 25 inline void copy(SkTArray<T, true>* self, const T* array) {
26 memcpy(self->fMemArray, array, self->fCount * sizeof(T)); 26 sk_careful_memcpy(self->fMemArray, array, self->fCount * sizeof(T));
27 } 27 }
28 template<typename T> 28 template<typename T>
29 inline void copyAndDelete(SkTArray<T, true>* self, char* newMemArray) { 29 inline void copyAndDelete(SkTArray<T, true>* self, char* newMemArray) {
30 memcpy(newMemArray, self->fMemArray, self->fCount * sizeof(T)); 30 sk_careful_memcpy(newMemArray, self->fMemArray, self->fCount * sizeof(T));
31 } 31 }
32 32
33 template<typename T> 33 template<typename T>
34 inline void copy(SkTArray<T, false>* self, int dst, int src) { 34 inline void copy(SkTArray<T, false>* self, int dst, int src) {
35 new (&self->fItemArray[dst]) T(self->fItemArray[src]); 35 new (&self->fItemArray[dst]) T(self->fItemArray[src]);
36 } 36 }
37 template<typename T> 37 template<typename T>
38 inline void copy(SkTArray<T, false>* self, const T* array) { 38 inline void copy(SkTArray<T, false>* self, const T* array) {
39 for (int i = 0; i < self->fCount; ++i) { 39 for (int i = 0; i < self->fCount; ++i) {
40 new (self->fItemArray + i) T(array[i]); 40 new (self->fItemArray + i) T(array[i]);
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 SkSTArray& operator= (const INHERITED& array) { 549 SkSTArray& operator= (const INHERITED& array) {
550 INHERITED::operator=(array); 550 INHERITED::operator=(array);
551 return *this; 551 return *this;
552 } 552 }
553 553
554 private: 554 private:
555 SkAlignedSTStorage<N,T> fStorage; 555 SkAlignedSTStorage<N,T> fStorage;
556 }; 556 };
557 557
558 #endif 558 #endif
OLDNEW
« no previous file with comments | « gyp/common_conditions.gypi ('k') | include/core/SkTDArray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698