From 03ee1e10021ab8f1ba1bd34d5b2be5423856eedc Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 10 Jul 2023 17:30:07 +0200 Subject: [PATCH] Fix assert in qCleanupFuncInfo when using QDebug from a lambda with auto ASSERT: "size_t(i) < size_t(size())" in file qbytearray.h, line 492 due to info being emptied out completely and then the code does while ((info.at(0) == '*') info was empty because the recent fix "that wasn't the function argument list" would exit the loop with pos at end. Incidentally, this change fixes the fact that qCleanupFuncInfo was removing lambdas: main(int, char**):: became main(int, char**):: which was, well, shorted, but weird. Change-Id: Ic7e8f21ea0df7ef96a3f25c4136a727dc0def207 Reviewed-by: Thiago Macieira (cherry picked from commit 056bdef045867dad07066351787b2edb771be569) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qlogging.cpp | 16 +++++++++++----- .../corelib/global/qlogging/tst_qlogging.cpp | 8 ++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index f45a321a6a5..9b0fbe37b5c 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1003,8 +1003,13 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) pos = info.size() - 1; if (info.endsWith(']') && !(info.startsWith('+') || info.startsWith('-'))) { while (--pos) { - if (info.at(pos) == '[') - info.truncate(pos); + if (info.at(pos) == '[') { + info.truncate(pos); + break; + } + } + if (info.endsWith(' ')) { + info.chop(1); } } @@ -1018,10 +1023,11 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) // canonize operator names info.replace("operator ", "operator"); + pos = -1; // remove argument list forever { int parencount = 0; - pos = info.lastIndexOf(')'); + pos = info.lastIndexOf(')', pos); if (pos == -1) { // Don't know how to parse this function name return info; @@ -1029,8 +1035,8 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) if (info.indexOf('>', pos) != -1 || info.indexOf(':', pos) != -1) { // that wasn't the function argument list. - pos = info.size(); - break; + --pos; + continue; } // find the beginning of the argument list diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index 665da3ff22b..0083cf4bfbe 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -625,6 +625,14 @@ void tst_qmessagehandler::cleanupFuncinfo_data() << "void `void function >(void)'::`2'::S::f(Polymorphic *)" << "function(void)'::`2'::S::f"; + QTest::newRow("gcc_lambda_1") << "main(int, char**)::" + << "main(int, char**)::"; + + QTest::newRow("gcc_lambda_with_auto_1") + << "SomeClass::someMethod(const QString&, const QString&):: [with " + "auto:57 = QNetworkReply::NetworkError]" + << "SomeClass::someMethod(const QString&, const QString&)::"; + QTest::newRow("objc_1") << "-[SomeClass someMethod:withArguments:]" << "-[SomeClass someMethod:withArguments:]";