OSDN Git Service

A NULL check in the memory allocation is added.
authortsutsumi <>
Wed, 1 Oct 2003 20:37:22 +0000 (20:37 +0000)
committertsutsumi <>
Wed, 1 Oct 2003 20:37:22 +0000 (20:37 +0000)
src/ccunit/CCUnitList.c

index 61d09c0..441de54 100755 (executable)
@@ -77,6 +77,8 @@ CCUnitList* ccunit_initList (CCUnitList* list)
 inline CCUnitList* ccunit_newList ()
 {
   CCUnitList* newList = calloc (1, sizeof (*newList));
+  if (!newList)
+    return NULL;
   ccunit_initList (newList);
   newList->isAllocated = true;
   return newList;
@@ -84,7 +86,12 @@ inline CCUnitList* ccunit_newList ()
 
 void ccunit_addList (CCUnitList* list, void* contents)
 {
-  CCUnitListCell* cell = ccunit_newListCell ();
+  CCUnitListCell* cell;
+  if (!list)
+    return;
+  cell = ccunit_newListCell ();
+  if (!cell)
+    return;
   cell->contents = contents;
   cell->next = NULL;
   *list->tailp = cell;
@@ -117,7 +124,12 @@ inline CCUnitListIterator* ccunit_initListIterator (const struct CCUnitList* lis
 
 CCUnitListIterator* ccunit_newListIterator (const struct CCUnitList* list)
 {
-  CCUnitListIterator* it = calloc (1, sizeof (*it));
+  CCUnitListIterator* it;
+  if (!list)
+    return NULL;
+  it = calloc (1, sizeof (*it));
+  if (!it)
+    return NULL;
   ccunit_initListIterator (list, it);
   it->isAllocated = true;
   return it;