Last active
October 30, 2017 16:59
-
-
Save jimblandy/cbca6862d15a9444fc3ce6afe9f906d2 to your computer and use it in GitHub Desktop.
Bug 1277377: Don't permit `.append((float*) ptr)` to a `Vector<int*>` π (patch from Luke)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/mfbt/Vector.h b/mfbt/Vector.h | |
--- a/mfbt/Vector.h | |
+++ b/mfbt/Vector.h | |
@@ -158,17 +158,22 @@ struct VectorImpl | |
*/ | |
template<typename T, size_t N, class AP> | |
struct VectorImpl<T, N, AP, true> | |
{ | |
template<typename... Args> | |
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*) {} | |
static inline void initialize(T* aBegin, T* aEnd) | |
{ | |
/* | |
* You would think that memset would be a big win (or even break even) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment