aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar krasin <krasin@google.com>2016-04-21 08:34:00 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-04-21 08:34:00 -0700
commite0c1d285a00e47e1d1584e6a35b95ef2f0d945ff (patch)
tree3ac626877602401cb52d887231a5ba7a8a2aab69 /include
parent8d7ffcee75661a50ce298dc1b3bc0b76bea018e7 (diff)
SkTArray: fix invalid reinterpret_casts over non-initialized memory.
This should fix 'CFI Linux' buildbot, which is currently horribly broken: https://build.chromium.org/p/chromium.fyi/builders/CFI%20Linux/builds/5115 BUG=605337 Review URL: https://codereview.chromium.org/1908763002
Diffstat (limited to 'include')
-rw-r--r--include/private/SkTArray.h29
1 files changed, 13 insertions, 16 deletions
diff --git a/include/private/SkTArray.h b/include/private/SkTArray.h
index 043784f093..8d8f6598db 100644
--- a/include/private/SkTArray.h
+++ b/include/private/SkTArray.h
@@ -159,34 +159,31 @@ public:
* elements.
*/
T& push_back() {
- T* newT = reinterpret_cast<T*>(this->push_back_raw(1));
- new (newT) T;
- return *newT;
+ void* newT = this->push_back_raw(1);
+ return *new (newT) T;
}
/**
* Version of above that uses a copy constructor to initialize the new item
*/
T& push_back(const T& t) {
- T* newT = reinterpret_cast<T*>(this->push_back_raw(1));
- new (newT) T(t);
- return *newT;
+ void* newT = this->push_back_raw(1);
+ return *new (newT) T(t);
}
/**
* Version of above that uses a move constructor to initialize the new item
*/
T& push_back(T&& t) {
- T* newT = reinterpret_cast<T*>(this->push_back_raw(1));
- new (newT) T(std::move(t));
- return *newT;
+ void* newT = this->push_back_raw(1);
+ return *new (newT) T(std::move(t));
}
/**
* Construct a new T at the back of this array.
*/
template<class... Args> T& emplace_back(Args&&... args) {
- T* newT = reinterpret_cast<T*>(this->push_back_raw(1));
+ void* newT = this->push_back_raw(1);
return *new (newT) T(std::forward<Args>(args)...);
}
@@ -197,11 +194,11 @@ public:
*/
T* push_back_n(int n) {
SkASSERT(n >= 0);
- T* newTs = reinterpret_cast<T*>(this->push_back_raw(n));
+ char* newTs = static_cast<char*>(this->push_back_raw(n));
for (int i = 0; i < n; ++i) {
- new (newTs + i) T;
+ new (newTs + i * sizeof(T)) T;
}
- return newTs;
+ return reinterpret_cast<T*>(newTs);
}
/**
@@ -210,11 +207,11 @@ public:
*/
T* push_back_n(int n, const T& t) {
SkASSERT(n >= 0);
- T* newTs = reinterpret_cast<T*>(this->push_back_raw(n));
+ char* newTs = static_cast<char*>(this->push_back_raw(n));
for (int i = 0; i < n; ++i) {
- new (newTs + i) T(t);
+ new (newTs + i * sizeof(T)) T(t);
}
- return newTs;
+ return reinterpret_cast<T*>(newTs);
}
/**