diff options
author | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-05-26 17:46:24 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-06-08 08:04:53 +0000 |
commit | ce0800060246e68fffc226b366cb4b0ea2e41ded (patch) | |
tree | 1a79104c19a84611d3207456438b4054703f2f56 /src/qml/jsruntime/qv4value_p.h | |
parent | fc83d811812d2e16f4139f6db7e357b5d2eb945b (diff) |
V4: tighten up various casts to check also check type.
All those type conversions assumed that the content of a Value was
either the requested type, or 0 (zero, a null pointer). Now, attempting
to convert e.g. undefined to a string will fail, instead of returning a
weird address.
Change-Id: I0f567cdcc9cc9728d019f17693f4a6007394a9c6
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4value_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index a8d9b0fa71..f99e24c6e9 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -286,16 +286,22 @@ struct Q_QML_PRIVATE_EXPORT Value } Q_ALWAYS_INLINE String *stringValue() const { + if (!isString()) + return nullptr; return m() ? reinterpret_cast<String*>(const_cast<Value *>(this)) : 0; } Q_ALWAYS_INLINE Object *objectValue() const { + if (!isObject()) + return nullptr; return m() ? reinterpret_cast<Object*>(const_cast<Value *>(this)) : 0; } Q_ALWAYS_INLINE Managed *managed() const { + if (!isManaged()) + return nullptr; return m() ? reinterpret_cast<Managed*>(const_cast<Value *>(this)) : 0; } Q_ALWAYS_INLINE Heap::Base *heapObject() const { - return m(); + return isManaged() ? m() : nullptr; } Q_ALWAYS_INLINE quint64 &rawValueRef() { @@ -357,7 +363,10 @@ struct Q_QML_PRIVATE_EXPORT Value } template <typename T> T *as() { - return const_cast<T *>(const_cast<const Value *>(this)->as<T>()); + if (isManaged()) + return const_cast<T *>(const_cast<const Value *>(this)->as<T>()); + else + return nullptr; } template<typename T> inline T *cast() { |