diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-12-17 16:27:23 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-12-17 16:27:23 -0800 |
| commit | 484e1e33da7477b7278c9a3e9da878f0375dd75b (patch) | |
| tree | 892979f8bf65fd9a1366c040fa4a090968fcaecf /grammar.c | |
| parent | 40be243004b095fe15bb2ece176692f8354cdf45 (diff) | |
Memory allocation failure checks, and a simpler new() function
Diffstat (limited to 'grammar.c')
| -rw-r--r-- | grammar.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -12,15 +12,15 @@ grammar_t *new_grammar(void) { - grammar_t *g = calloc(sizeof(grammar_t), 1); - g->definitions = calloc(sizeof(def_t), (g->defcapacity = 128)); + grammar_t *g = new(grammar_t); + g->definitions = xcalloc(sizeof(def_t), (g->defcapacity = 128)); return g; } void add_def(grammar_t *g, file_t *f, const char *src, const char *name, vm_op_t *op) { if (g->defcount >= g->defcapacity) { - g->definitions = realloc(g->definitions, sizeof(&g->definitions[0])*(g->defcapacity += 32)); + g->definitions = xrealloc(g->definitions, sizeof(&g->definitions[0])*(g->defcapacity += 32)); } int i = g->defcount; g->definitions[i].file = f; @@ -84,12 +84,12 @@ vm_op_t *lookup(grammar_t *g, const char *name) void push_backref(grammar_t *g, const char *name, match_t *capture) { if (g->backrefcount >= g->backrefcapacity) { - g->backrefs = realloc(g->backrefs, sizeof(g->backrefs[0])*(g->backrefcapacity += 32)); + g->backrefs = xrealloc(g->backrefs, sizeof(g->backrefs[0])*(g->backrefcapacity += 32)); } size_t i = g->backrefcount++; g->backrefs[i].name = name; g->backrefs[i].capture = capture; - vm_op_t *op = calloc(sizeof(vm_op_t), 1); + vm_op_t *op = new(vm_op_t); op->op = VM_BACKREF; op->start = capture->start; op->end = capture->end; |
