Fix QTest::qExec crash with no command line arguments
authorJeremy Lainé <jeremy.laine@m4x.org>
Tue, 4 Sep 2012 14:04:19 +0000 (16:04 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 7 Sep 2012 23:44:26 +0000 (01:44 +0200)
The documentation for QTest::qExec states that command line arguments
are optional and gives the following example:

 MyTestObject test1;
 QTest::qExec(&test1);

However, running this example leads to crash as argv[0] is accessed
without testing argc. This change fixes this bug.

Change-Id: I2ec016e02869d21b24bc11f1851a760036640191
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Jason McDonald <macadder1@gmail.com>
src/testlib/qtestcase.cpp

index 3bd6848..11d7f68 100644 (file)
@@ -2114,7 +2114,8 @@ int QTest::qExec(QObject *testObject, int argc, char **argv)
     QTEST_ASSERT(metaObject);
 
     QTestResult::setCurrentTestObject(metaObject->className());
-    QTestResult::setCurrentAppname(argv[0]);
+    if (argc > 0)
+        QTestResult::setCurrentAppname(argv[0]);
 
     qtest_qParseArgs(argc, argv, false);