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>
bb10
Stanislav Ionascu 2014-02-28 21:44:22 +01:00 committed by The Qt Project
parent 3b00cc4804
commit 2989b65afd
1 changed files with 8 additions and 2 deletions

View File

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