From f6735dba9518ffc896541f212fade350e18c91de Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 15 Aug 2023 10:30:44 +0200 Subject: QmlCompiler: Fix console logging Store a copy of the UTF-8 data for file and function so that we don't run into heap-use-after-free. Set the instruction pointer before calling the log function so that we get a correct line number. Pick-to: 6.6 6.5 Fixes: QTBUG-114655 Change-Id: I38249fe52719ddad620033716ff22b2087ab8382 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index f7f2182796..a42491c12a 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -993,7 +993,8 @@ void tst_QmlCppCodegen::compositeTypeMethod() void tst_QmlCppCodegen::consoleObject() { QQmlEngine engine; - QQmlComponent c(&engine, QUrl(u"qrc:/qt/qml/TestTypes/consoleObject.qml"_s)); + static const QString urlString = u"qrc:/qt/qml/TestTypes/consoleObject.qml"_s; + QQmlComponent c(&engine, QUrl(urlString)); QVERIFY2(c.isReady(), qPrintable(c.errorString())); QTest::ignoreMessage(QtDebugMsg, "b 4.55"); @@ -1026,6 +1027,17 @@ void tst_QmlCppCodegen::consoleObject() QScopedPointer o(c.create()); QVERIFY(!o.isNull()); + + auto oldHandler = qInstallMessageHandler( + [](QtMsgType, const QMessageLogContext &ctxt, const QString &) { + QCOMPARE(ctxt.file, urlString.toUtf8()); + QCOMPARE(ctxt.function, QByteArray("expression for onCompleted")); + QVERIFY(ctxt.line > 0); + }); + const auto guard = qScopeGuard([oldHandler]() { qInstallMessageHandler(oldHandler); }); + + QScopedPointer p(c.create()); + QVERIFY(!p.isNull()); } void tst_QmlCppCodegen::construct() -- cgit v1.2.3