diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-15 10:30:44 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-08-15 17:48:43 +0200 |
commit | f6735dba9518ffc896541f212fade350e18c91de (patch) | |
tree | 747b22fbd78c504b2d05acbbe90c849bf62e0d1a /src | |
parent | afb57dfa06fb7e8be47ac1118758421cfe31ba3e (diff) |
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/qqml.cpp | 6 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljscodegenerator.cpp | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/qml/qml/qqml.cpp b/src/qml/qml/qqml.cpp index f951fb6a14..1e051fd37a 100644 --- a/src/qml/qml/qqml.cpp +++ b/src/qml/qml/qqml.cpp @@ -1472,8 +1472,10 @@ void AOTCompiledContext::writeToConsole( const QV4::CppStackFrame *frame = engine->handle()->currentStackFrame; Q_ASSERT(frame); - QMessageLogger logger(qUtf8Printable(frame->source()), frame->lineNumber(), - qUtf8Printable(frame->function()), loggingCategory->categoryName()); + const QByteArray source(frame->source().toUtf8()); + const QByteArray function(frame->function().toUtf8()); + QMessageLogger logger(source.constData(), frame->lineNumber(), + function.constData(), loggingCategory->categoryName()); switch (type) { case QtDebugMsg: diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp index 96f02a55c9..e1a461d6c2 100644 --- a/src/qmlcompiler/qqmljscodegenerator.cpp +++ b/src/qmlcompiler/qqmljscodegenerator.cpp @@ -1730,8 +1730,8 @@ bool QQmlJSCodeGenerator::inlineConsoleMethod(const QString &name, int argc, int } else { m_body += u"QString()"; } - m_body += u";\n"; - + m_body += u";\n "; + generateSetInstructionPointer(); m_body += u" aotContext->writeToConsole(" + type + u", message, category);\n"; m_body += u" }\n"; m_body += u"}\n"; |