diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-07-09 19:50:57 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-07-09 21:00:37 +0200 |
commit | 0cfb44bf2972dc006ec6042b676f86d6059d0890 (patch) | |
tree | d3c8f7d0e850676609eef2615dd80f15debc5fca /src/qml/qml/qqmlvaluetypewrapper.cpp | |
parent | c25c2b73a4689f9f4dbdbb0034db98643c8156ce (diff) |
Fix QQmlValueTypeWrapper::method_toString()
QMetaType::convert() is notoriously hard to use. You cannot keep the
QString on the stack as QString because its dtor will unconditionally be
called when the scope is left, no matter if the conversion succeeded.
Therefore, keep an array of quint8 on the stack and manually call the
dtor if the conversion succeeds.
Change-Id: If7970ff6adb4cc2a822a065f9f07130065ce9502
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlvaluetypewrapper.cpp')
-rw-r--r-- | src/qml/qml/qqmlvaluetypewrapper.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index d10fad191c..9407020614 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -362,10 +362,11 @@ ReturnedValue QQmlValueTypeWrapper::method_toString(const FunctionObject *b, con QString result; // Prepare a buffer to pass to QMetaType::convert() - QString convertResult; - convertResult.~QString(); + alignas(alignof(QString)) unsigned char convertResult[sizeof(QString)]; if (QMetaType::convert(w->d()->gadgetPtr(), w->d()->valueType()->metaType.id(), &convertResult, QMetaType::QString)) { - result = convertResult; + QString &string = reinterpret_cast<QString &>(convertResult); + result = string; + string.~QString(); } else { result += QString::fromUtf8(QMetaType::typeName(w->d()->valueType()->metaType.id())) + QLatin1Char('('); |