From e574e0eda098be1e877be7b6f92e77f82ff8fc84 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Thu, 2 Jun 2016 14:38:02 -0500 Subject: [PATCH] Bug 1277377 - prevent unsafe C-style cast in Vector (r=waldo) MozReview-Commit-ID: L0bTDSBHOeY --- mfbt/Vector.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mfbt/Vector.h b/mfbt/Vector.h index f31aeee731a6..23a299f3b21f 100644 --- a/mfbt/Vector.h +++ b/mfbt/Vector.h @@ -163,7 +163,12 @@ struct VectorImpl MOZ_NONNULL(1) static inline void new_(T* aDst, Args&&... aArgs) { - *aDst = T(Forward(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(aArgs)...); + *aDst = temp; } static inline void destroy(T*, T*) {}