From 2989b65afd497744ac08b3c55cc4f75908c46ecf Mon Sep 17 00:00:00 2001 From: Stanislav Ionascu Date: Fri, 28 Feb 2014 21:44:22 +0100 Subject: [PATCH] Testlib: Fix minor leak and crash when comparing lists 1) toString does not track the string it returns, thus it has to be deleted by the caller 2) on some platforms vsnprintf crashes if a null string is in the va_list Change-Id: Iecf94e93d3a2ddf4186ee20de1f495f2f92dcc60 Reviewed-by: Olivier Goffart --- src/testlib/qtest.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 7c9a7b2b3f..7d2f3cea72 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -201,11 +201,17 @@ inline bool qCompare(QList const &t1, QList const &t2, const char *actual, } for (int i = 0; isOk && i < actualSize; ++i) { if (!(t1.at(i) == t2.at(i))) { + char *val1 = toString(t1.at(i)); + char *val2 = toString(t2.at(i)); + qsnprintf(msg, sizeof(msg), "Compared lists differ at index %d.\n" " Actual (%s): %s\n" - " Expected (%s): %s", i, actual, toString(t1.at(i)), - expected, toString(t2.at(i))); + " Expected (%s): %s", i, actual, val1 ? val1 : "", + expected, val2 ? val2 : ""); isOk = false; + + delete [] val1; + delete [] val2; } } return compare_helper(isOk, msg, 0, 0, actual, expected, file, line);