comparison c/regexParser/createRegexParser.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 3eb3cb5d581f
children ec485345daf9
comparison
equal deleted inserted replaced
107:c9f5ee891b5e 108:70069d4647a0
15 * regexPosition(state) 15 * regexPosition(state)
16 * stateTransitionTable 16 * stateTransitionTable
17 */ 17 */
18 NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) { 18 NodePtr createNode(RegexInfoPtr ri,unsigned char character, NodePtr left, NodePtr right) {
19 NodePtr n = (NodePtr)malloc(sizeof(Node)); 19 NodePtr n = (NodePtr)malloc(sizeof(Node));
20 if (n == NULL) {
21 fprintf(stderr, "Failed to allocate memory.\n");
22 exit(-1);
23 }
24
20 n->tokenType = ri->tokenType; 25 n->tokenType = ri->tokenType;
21 n->self = n; 26 n->self = n;
22 n->Value.character = character; 27 n->Value.character = character;
23 n->left = left; 28 n->left = left;
24 n->right = right; 29 n->right = right;
39 } 44 }
40 45
41 // <charClass> ::= '['<literal>'-'<literal>']' 46 // <charClass> ::= '['<literal>'-'<literal>']'
42 NodePtr charClass(RegexInfoPtr ri) { 47 NodePtr charClass(RegexInfoPtr ri) {
43 NodePtr n = (NodePtr)malloc(sizeof(Node)); 48 NodePtr n = (NodePtr)malloc(sizeof(Node));
49 if (n == NULL) {
50 fprintf(stderr, "Failed to allocate memory.\n");
51 exit(-1);
52 }
44 while (ri->ptr[0] == '-') { 53 while (ri->ptr[0] == '-') {
45 ri->ptr++; 54 ri->ptr++;
46 } 55 }
47 return n; 56 return n;
48 } 57 }