aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-09-23 07:37:22 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-09-23 08:43:07 +0200
commita90f7fc640d612a2524f6bb1522d786960e3a573 (patch)
tree42f4671e8583b3d2771f7ffa51e2f4229efd5980 /src
parent149c1dd07b54ee0c027d94a49d52160dc4f4e2ac (diff)
Avoid crash when module version cannot be resolved
When QQmlMetaType::latestModuleVersion() returned an invalid version, we would fail importStaticPlugin() without adding any error. Since we unconditionally called takeFirst() on the errors list, we would later crash. The precondition here is that any failure adds an error, so we now assert to make this explicit. Also, add a simple module not found error when we can't resolve it. Change-Id: I7a13775b2ef56d95b7738ac53e58501b8c68895f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/qqmlimport.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index 840715c847..c4ca167c85 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -1264,6 +1264,7 @@ QTypeRevision QQmlImportsPrivate::importExtension(
instance, basePath, uri, typeNamespace, version, errors);
if (!version.isValid()){
if (errors) {
+ Q_ASSERT(!errors->isEmpty());
QQmlError poppedError = errors->takeFirst();
QQmlError error;
error.setDescription(QQmlImportDatabase::tr("static plugin for module \"%1\" with name \"%2\" cannot be loaded: %3")
@@ -2220,8 +2221,11 @@ void QQmlImportDatabase::setImportPathList(const QStringList &paths)
static QTypeRevision lockModule(const QString &uri, const QString &typeNamespace,
QTypeRevision version, QList<QQmlError> *errors)
{
- if (!version.hasMajorVersion())
+ if (!version.hasMajorVersion()) {
version = QQmlMetaType::latestModuleVersion(uri);
+ if (!version.isValid())
+ errors->prepend(moduleNotFoundError(uri, version));
+ }
if (version.hasMajorVersion() && !typeNamespace.isEmpty()
&& !QQmlMetaType::protectModule(uri, version, true)) {
// Not being able to protect the module means there are not types registered for it,