summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStanislav Ionascu <stanislav.ionascu@gmail.com>2014-02-28 21:44:22 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-06 22:37:23 +0200
commit2989b65afd497744ac08b3c55cc4f75908c46ecf (patch)
tree34148f1b418d7c082968a7ea24488996b7f629c6
parent3b00cc480400d47c59c29d3507c7fcdc9be2a489 (diff)
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 <ogoffart@woboq.com>
-rw-r--r--src/testlib/qtest.h10
1 files 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<T> const &t1, QList<T> 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 : "<null>",
+ expected, val2 ? val2 : "<null>");
isOk = false;
+
+ delete [] val1;
+ delete [] val2;
}
}
return compare_helper(isOk, msg, 0, 0, actual, expected, file, line);