comparison 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
comparison
equal deleted inserted replaced
107:c9f5ee891b5e 108:70069d4647a0
8 int bitBlock = sizeof(unsigned long) * 8; 8 int bitBlock = sizeof(unsigned long) * 8;
9 9
10 BitVectorPtr bitSet(int bitSetPosition) { 10 BitVectorPtr bitSet(int bitSetPosition) {
11 11
12 BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector)); 12 BitVectorPtr bi = (BitVectorPtr)malloc(sizeof(BitVector));
13 if (bi == NULL) {
14 fprintf(stderr, "Failed to allocate memory.\n");
15 exit(-1);
16 }
17
13 bi->bitContainer = (unsigned long*)malloc(sizeof(unsigned long)*bi->arrayNum); 18 bi->bitContainer = (unsigned long*)malloc(sizeof(unsigned long)*bi->arrayNum);
19 if (bi->bitContainer == NULL) {
20 fprintf(stderr, "Failed to allocate memory.\n");
21 exit(-1);
22 }
14 23
15 bi->arrayNum = (bitSetPosition + 1) / bitBlock; 24 bi->arrayNum = (bitSetPosition + 1) / bitBlock;
16 if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++; 25 if (((bitSetPosition + 1) % bitBlock) != 0) bi->arrayNum++;
17 26
18 for (int i = 0; i < bi->arrayNum; i++) { 27 for (int i = 0; i < bi->arrayNum; i++) {