diff c/regexParser/bitVector.cc @ 108:70069d4647a0 impl-bitvector

implement malloc error checking
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 19 Nov 2015 17:48:36 +0900
parents d0d2262d4edf
children a3adc5c24e19
line wrap: on
line diff
--- a/c/regexParser/bitVector.cc	Thu Nov 19 17:23:06 2015 +0900
+++ b/c/regexParser/bitVector.cc	Thu Nov 19 17:48:36 2015 +0900
@@ -10,7 +10,16 @@
 BitVectorPtr bitSet(int bitSetPosition) {
 
     BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector));
+    if (bi == NULL) {
+        fprintf(stderr, "Failed to allocate memory.\n");
+        exit(-1);
+    }
+
     bi->bitContainer = (unsigned long*)malloc(sizeof(unsigned long)*bi->arrayNum);
+    if (bi->bitContainer == NULL) {
+        fprintf(stderr, "Failed to allocate memory.\n");
+        exit(-1);
+    }
 
     bi->arrayNum = (bitSetPosition + 1) / bitBlock;
     if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++;