From: tsntsumi Date: Wed, 1 Oct 2003 20:54:17 +0000 (+0000) Subject: A NULL check in the memory allocation is added. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7bd58d5209a3fe5794aa41657102a6168d9b0eea;p=ccunit%2Fccunit.git A NULL check in the memory allocation is added. --- diff --git a/src/ccunit/CCUnitTestSuite.c b/src/ccunit/CCUnitTestSuite.c index 08c0104..6d37c9d 100755 --- a/src/ccunit/CCUnitTestSuite.c +++ b/src/ccunit/CCUnitTestSuite.c @@ -76,8 +76,13 @@ inline CCUnitTestSuite* ccunit_newTestSuite (const char* name) CCUnitTestSuite* ccunit_newTestSuiteFromDfn (const CCUnitTestSuiteDfn* sdp) { - CCUnitTestSuite* suite = ccunit_newTestSuite (sdp->name); + CCUnitTestSuite* suite; CCUnitTestDfn** tdpp; + if (!sdp) + return NULL; + suite = ccunit_newTestSuite (sdp->name); + if (!suite) + return NULL; for (tdpp = (CCUnitTestDfn**)sdp->tests; *tdpp; tdpp ++) { const CCUnitTestDfn* tdp = *tdpp; @@ -85,20 +90,31 @@ CCUnitTestSuite* ccunit_newTestSuiteFromDfn (const CCUnitTestSuiteDfn* sdp) { CCUnitTestSuite* sp; sp = ccunit_newTestSuiteFromDfn ((CCUnitTestSuiteDfn*)tdp); + if (sp) + ccunit_addTestSuite (suite, sp); } else if (tdp->type == ccunitTypeFixture) { - const CCUnitTestFixtureDfn* fdp = (CCUnitTestFixtureDfn*)tdp; + CCUnitTestFixtureDfn* fdp = (CCUnitTestFixtureDfn*)tdp; CCUnitTestFixture* fp; CCUnitTestCase* cd; - fp = ccunit_newTestFixture (fdp->name, fdp->setUp, fdp->tearDown, - fdp->ctor, fdp->dtor); - ccunit_addTestFixture (suite, fp); - for (cd = (CCUnitTestCase*)fdp->testCases; cd->name; cd ++) + fp = ccunit_newTestFixture (fdp->name, + ccunit_newTestFunc (fdp->setUp.name, + fdp->setUp.desc, + fdp->setUp.runTest), + ccunit_newTestFunc (fdp->tearDown.name, + fdp->tearDown.desc, + fdp->tearDown.runTest)); + if (fp) { - CCUnitTestCase* cp; - cp = ccunit_newTestCase (cd->name, cd->desc, cd->runTest); - ccunit_addTestCase (fp, cp); + ccunit_addTestFixture (suite, fp); + for (cd = (CCUnitTestCase*)fdp->testCases; cd->name; cd ++) + { + CCUnitTestCase* cp; + cp = ccunit_newTestCase (cd->name, cd->desc, cd->runTest); + if (cp) + ccunit_addTestCase (fp, cp); + } } } } @@ -131,7 +147,11 @@ inline CCUnitTestResult* ccunit_runTestSuite (CCUnitTestSuite* suite, CCUnitTestResult* result) { if (!result) - result = ccunit_newTestResult (); + { + result = ccunit_newTestResult (); + if (!result) + return NULL; + } suite->test.run (&suite->test, result); return result; }