un-crash QPlainTestLogger::printMessage()
Commitcf4a611115
refactored out test identifier buildup into a standalone function, but it returned the QTestCharBuffer as a value type, which ultimately caused it to crash: Unfortunately QTestCharBuffer is not copied correctly: Since it uses the default copy ctor it will copy the buf pointer and create a deep copy of the staticBuf pointer. When the dtor was later called it would then end up calling free(buf) (where buf pointed to the staticBuf of the original QTestCharBuffer). Task-number: QTBUG-66607 Change-Id: Ifa290658be6f077a0d6613451c26aeeffc8df41c Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit6ffb358822
) Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
d266ac3a6b
commit
2dc578a8f2
@ -223,10 +223,8 @@ void QPlainTestLogger::outputMessage(const char *str)
|
|||||||
outputString(str);
|
outputString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QTestCharBuffer testIdentifier()
|
static void testIdentifier(QTestCharBuffer *identifier)
|
||||||
{
|
{
|
||||||
QTestCharBuffer identifier;
|
|
||||||
|
|
||||||
const char *testObject = QTestResult::currentTestObjectName();
|
const char *testObject = QTestResult::currentTestObjectName();
|
||||||
const char *testFunction = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() : "UnknownTestFunc";
|
const char *testFunction = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() : "UnknownTestFunc";
|
||||||
|
|
||||||
@ -234,8 +232,7 @@ static QTestCharBuffer testIdentifier()
|
|||||||
const char *globalDataTag = QTestResult::currentGlobalDataTag() ? QTestResult::currentGlobalDataTag() : "";
|
const char *globalDataTag = QTestResult::currentGlobalDataTag() ? QTestResult::currentGlobalDataTag() : "";
|
||||||
const char *tagFiller = (dataTag[0] && globalDataTag[0]) ? ":" : "";
|
const char *tagFiller = (dataTag[0] && globalDataTag[0]) ? ":" : "";
|
||||||
|
|
||||||
QTest::qt_asprintf(&identifier, "%s::%s(%s%s%s)", testObject, testFunction, globalDataTag, tagFiller, dataTag);
|
QTest::qt_asprintf(identifier, "%s::%s(%s%s%s)", testObject, testFunction, globalDataTag, tagFiller, dataTag);
|
||||||
return identifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line)
|
void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line)
|
||||||
@ -256,8 +253,10 @@ void QPlainTestLogger::printMessage(const char *type, const char *msg, const cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *msgFiller = msg[0] ? " " : "";
|
const char *msgFiller = msg[0] ? " " : "";
|
||||||
|
QTestCharBuffer testIdent;
|
||||||
|
testIdentifier(&testIdent);
|
||||||
QTest::qt_asprintf(&messagePrefix, "%s: %s%s%s%s\n",
|
QTest::qt_asprintf(&messagePrefix, "%s: %s%s%s%s\n",
|
||||||
type, testIdentifier().data(), msgFiller, msg, failureLocation.data());
|
type, testIdent.data(), msgFiller, msg, failureLocation.data());
|
||||||
|
|
||||||
// In colored mode, printf above stripped our nonprintable control characters.
|
// In colored mode, printf above stripped our nonprintable control characters.
|
||||||
// Put them back.
|
// Put them back.
|
||||||
|
Loading…
Reference in New Issue
Block a user