aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-06-01 11:02:56 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-06-06 13:12:35 +0200
commit3835bf97e01c3457dcca438006dd523f6442f657 (patch)
tree50e27e409a8ad14b7648f35226d3df6cab049e0c
parent8d1847b4587b5f57919062930ca9cbc8f593c9c8 (diff)
QtQml: Disallow multi-step construction of value types
If we coerce the argument for a constructor, we should not call another constructor in the process. Such chaining leads to rather confusing effects and easily ends in infinite recursion. Change-Id: Ia6d5063641170d2cd3bee3fdcbb8b97837d5c700 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit b4ce8051af0110e3a081ec83d1c8ff953243e07c) Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
-rw-r--r--src/qml/qml/qqmlglobal.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlglobal.cpp b/src/qml/qml/qqmlglobal.cpp
index 265b26b1e0..8653ef0783 100644
--- a/src/qml/qml/qqmlglobal.cpp
+++ b/src/qml/qml/qqmlglobal.cpp
@@ -98,12 +98,11 @@ static bool fromMatchingType(
return true;
}
- QVariant converted(parameterType);
- if (QQmlValueTypeProvider::createValueType(s, parameterType, converted.data())) {
- callConstructor(mo, i, converted.data(), metaType, data);
- return true;
- }
+ // Do not recursively try to create parameters here. This may end up in infinite recursion.
+ // At this point, s should be a builtin type. For builtin types
+ // the QMetaType converters are good enough.
+ QVariant converted(parameterType);
if (QMetaType::convert(parameter.metaType(), parameter.constData(),
parameterType, converted.data())) {
callConstructor(mo, i, converted.data(), metaType, data);
@@ -135,14 +134,11 @@ static bool fromMatchingType(
return true;
}
- QVariant parameter(parameterType);
- if (QQmlValueTypeProvider::createValueType(s, parameterType, parameter.data())) {
- callConstructor(mo, i, parameter.data(), metaType, data);
- return true;
- }
+ // Do not recursively try to create parameters here. This may end up in infinite recursion.
// At this point, s should be a builtin type. For builtin types
// the QMetaType converters are good enough.
+ QVariant parameter(parameterType);
if (QMetaType::convert(sourceMetaType, s.constData(), parameterType, parameter.data())) {
callConstructor(mo, i, parameter.data(), metaType, data);
return true;