From d78fab531a34ee911e373eaef0fbf3626b74c07c Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Thu, 8 Mar 2012 11:20:41 +1000 Subject: [PATCH] testlib: Make QTestResult::verify() more robust. The statementStr parameter should always be non-null, so assert if it is null. The description parameter can be null in some cases (particularly when the verify is successful, and thus no error description is going to be displayed), so tolerate this. Change-Id: I87b416d5f3b793bc608cd4aca14a4f7fe7527488 Reviewed-by: Rohan McGovern --- src/testlib/qtestresult.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index 231fc8f3b1..cbededfee2 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -230,6 +230,8 @@ static bool checkStatement(bool statement, const char *msg, const char *file, in bool QTestResult::verify(bool statement, const char *statementStr, const char *description, const char *file, int line) { + QTEST_ASSERT(statementStr); + char msg[1024]; if (QTestLog::verboseLevel() >= 2) { @@ -240,7 +242,7 @@ bool QTestResult::verify(bool statement, const char *statementStr, const char * format = QTest::expectFailMode ? "'%s' returned TRUE unexpectedly. (%s)" : "'%s' returned FALSE. (%s)"; - qsnprintf(msg, 1024, format, statementStr, description); + qsnprintf(msg, 1024, format, statementStr, description ? description : ""); return checkStatement(statement, msg, file, line); }