Bug 1277377 - prevent unsafe C-style cast in Vector (r=waldo)

MozReview-Commit-ID: L0bTDSBHOeY
This commit is contained in:
Luke Wagner 2016-06-02 14:38:02 -05:00
parent 38784200aa
commit e574e0eda0

View File

@ -163,7 +163,12 @@ struct VectorImpl<T, N, AP, true>
MOZ_NONNULL(1)
static inline void new_(T* aDst, Args&&... aArgs)
{
*aDst = T(Forward<Args>(aArgs)...);
// Explicitly construct a local object instead of using a temporary since
// T(args...) will be treated like a C-style cast in the unary case and
// allow unsafe conversions. Both forms should be equivalent to an
// optimizing compiler.
T temp(Forward<Args>(aArgs)...);
*aDst = temp;
}
static inline void destroy(T*, T*) {}