From 3110117bfaa36c5363bfa46cd82b01ff6723dd8d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 5 Jul 2023 13:12:01 +0200 Subject: QML: Check result when constructing object from metaobject If you pass insufficient arguments to call the ctor, the resulting object is null and cannot be used. Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-114910 Change-Id: Ib184684b6a7665bcdc1a3fe8f8a2401a33a8ac1c Reviewed-by: Semih Yavuz Reviewed-by: Fabian Kosmale --- src/qml/jsruntime/qv4qobjectwrapper.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/qml/jsruntime/qv4qobjectwrapper.cpp') diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 38b9226c9f..14a4c67f96 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -2786,9 +2786,11 @@ ReturnedValue QMetaObjectWrapper::constructInternal(const Value *argv, int argc) objectOrGadget, d()->constructors, d()->constructorCount, v4, callData)) { object = CallPrecise(objectOrGadget, *ctor, v4, callData, QMetaObject::CreateInstance); } - Scoped metaObject(scope, this); - object->defineDefaultProperty(v4->id_constructor(), metaObject); - object->setPrototypeOf(const_cast(this)); + if (object) { + Scoped metaObject(scope, this); + object->defineDefaultProperty(v4->id_constructor(), metaObject); + object->setPrototypeOf(const_cast(this)); + } return object.asReturnedValue(); } -- cgit v1.2.3