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**)::<lambda()>
became
  main(int, char**)::
which was, well, shorted, but weird.

Pick-to: 6.6 6.5
Change-Id: Ic7e8f21ea0df7ef96a3f25c4136a727dc0def207
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2023-07-10 17:30:07 +02:00
parent 8c18a245b0
commit 056bdef045
2 changed files with 19 additions and 5 deletions

View File

@ -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

View File

@ -625,6 +625,14 @@ void tst_qmessagehandler::cleanupFuncinfo_data()
<< "void `void function<Polymorphic<void __cdecl(int *)> >(void)'::`2'::S::f(Polymorphic<void __cdecl(int *)> *)"
<< "function(void)'::`2'::S::f";
QTest::newRow("gcc_lambda_1") << "main(int, char**)::<lambda()>"
<< "main(int, char**)::<lambda()>";
QTest::newRow("gcc_lambda_with_auto_1")
<< "SomeClass::someMethod(const QString&, const QString&)::<lambda(auto:57)> [with "
"auto:57 = QNetworkReply::NetworkError]"
<< "SomeClass::someMethod(const QString&, const QString&)::<lambda(auto:57)>";
QTest::newRow("objc_1")
<< "-[SomeClass someMethod:withArguments:]"
<< "-[SomeClass someMethod:withArguments:]";