# HG changeset patch # User Masataka Kohagura # Date 1447922916 -32400 # Node ID 70069d4647a053a13759a841e38d19a4b50d563f # Parent c9f5ee891b5ed0da08da4207fdf1b02999a9b9fd implement malloc error checking diff -r c9f5ee891b5e -r 70069d4647a0 c/regexParser/bitVector.cc --- 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++; diff -r c9f5ee891b5e -r 70069d4647a0 c/regexParser/createBitVectorList.cc --- a/c/regexParser/createBitVectorList.cc Thu Nov 19 17:23:06 2015 +0900 +++ b/c/regexParser/createBitVectorList.cc Thu Nov 19 17:48:36 2015 +0900 @@ -14,8 +14,18 @@ BitVectorListPtr allocateBitVectorList() { BitVectorListPtr bvl = (BitVectorListPtr)malloc(sizeof(BitVectorList)); + if (bvl == NULL) { + fprintf(stderr, "Failed to allocate memory.\n"); + exit(-1); + } + bvl->self = bvl; bvl->bi = (BitVectorPtr)malloc(sizeof(BitVector)); + if (bvl->bi == NULL) { + fprintf(stderr, "Failed to allocate memory.\n"); + exit(-1); + } + return bvl; } diff -r c9f5ee891b5e -r 70069d4647a0 c/regexParser/createRegexParser.cc --- a/c/regexParser/createRegexParser.cc Thu Nov 19 17:23:06 2015 +0900 +++ b/c/regexParser/createRegexParser.cc Thu Nov 19 17:48:36 2015 +0900 @@ -17,6 +17,11 @@ */ NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) { NodePtr n = (NodePtr)malloc(sizeof(Node)); + if (n == NULL) { + fprintf(stderr, "Failed to allocate memory.\n"); + exit(-1); + } + n->tokenType = ri->tokenType; n->self = n; n->Value.character = character; @@ -41,6 +46,10 @@ // ::= '[''-'']' NodePtr charClass(RegexInfoPtr ri) { NodePtr n = (NodePtr)malloc(sizeof(Node)); + if (n == NULL) { + fprintf(stderr, "Failed to allocate memory.\n"); + exit(-1); + } while (ri->ptr[0] == '-') { ri->ptr++; }