diff options
author | Jędrzej Nowacki <jedrzej.nowacki@nokia.com> | 2012-04-18 14:40:50 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-19 01:57:58 +0200 |
commit | b3e55fbf4ec8b260d358640808ea459a5125049b (patch) | |
tree | bbd4720cdff2459f8fd8c1b0f14456faf944042e /src/corelib/kernel | |
parent | 06d4ea64001f7d7c019f5dac5080d80e37828c3d (diff) |
Do not assert when QVariant is constructed from an invalid type id
That change also fix moduleForType() which was wrongly recognizing
negative ids as belonging to Core.
New tests were added.
Change-Id: I40a5819effb32489a45937011980457387c9f8be
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qmetatype_p.h | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index 2ab4a3896f..985cf71974 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE namespace QModulesPrivate { enum Names { Core, Gui, Widgets, Unknown, ModulesCount /* ModulesCount has to be at the end */ }; -static inline int moduleForType(const int typeId) +static inline int moduleForType(const uint typeId) { if (typeId <= QMetaType::LastCoreType) return Core; diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 47c87098f8..296b845469 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -87,7 +87,7 @@ class HandlersManager { static const QVariant::Handler *Handlers[QModulesPrivate::ModulesCount]; public: - const QVariant::Handler *operator[] (const int typeId) const + const QVariant::Handler *operator[] (const uint typeId) const { return Handlers[QModulesPrivate::moduleForType(typeId)]; } @@ -776,6 +776,7 @@ static void customConstruct(QVariant::Private *d, const void *copy) const QMetaType type(d->type); const uint size = type.sizeOf(); if (!size) { + qWarning("Trying to construct an instance of an invalid type, type id: %i", d->type); d->type = QVariant::Invalid; return; } @@ -1700,7 +1701,7 @@ void QVariant::load(QDataStream &s) return; } } - create(static_cast<int>(typeId), 0); + create(typeId, 0); d.is_null = is_null; if (!isValid()) { |