diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-12-03 00:04:40 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2024-12-03 00:04:40 +0000 |
commit | 9bbfa7d2cd5b46f07052dfb2212d792cb6f2641d (patch) | |
tree | 25841d1585df85161bf91e864c626eb5713dd262 /parser.c | |
parent | 623b3acc1f8b719b15523982ff5ed04eb85b19d5 (diff) | |
download | obf-9bbfa7d2cd5b46f07052dfb2212d792cb6f2641d.tar.gz obf-9bbfa7d2cd5b46f07052dfb2212d792cb6f2641d.tar.bz2 obf-9bbfa7d2cd5b46f07052dfb2212d792cb6f2641d.zip |
Some general reworking, error handling
Diffstat (limited to 'parser.c')
-rw-r--r-- | parser.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -11,6 +11,13 @@ char *ast_to_str(node_t *ast, size_t size) { char *out = calloc(size + 1, 1); + if (!out) + { + print_error( + "[internal]", 0, 0, + "ERROR: Out of Memory (could not allocate buffer in ast_to_str)"); + return NULL; + } for (size_t i = 0; i < size; ++i) { switch (ast[i].type) @@ -49,6 +56,8 @@ struct PResult parse_buffer(buffer_t *buffer) { node_t *nodes = NULL; size_t usable = 0, loops = 0; + + // First pass: Compute |nodes| for (size_t i = 0; i < buffer->size; ++i) if (usable_character(buffer->data[i])) { @@ -57,8 +66,15 @@ struct PResult parse_buffer(buffer_t *buffer) ++loops; } nodes = calloc(usable, sizeof(*nodes)); + if (!nodes) + { + print_error( + "[internal]", 0, 0, + "ERROR: Out of Memory (could not allocate buffer in parse_buffer)"); + return (struct PResult){0}; + } - // First pass: Get my info + // Second pass: parse nodes for (size_t i = 0, col = 0, row = 1, nptr = 0; i < buffer->size; ++i) { ++col; @@ -104,7 +120,7 @@ struct PResult parse_buffer(buffer_t *buffer) } } - // Second pass: setup any loop references + // Third pass: setup loop references node_t *stack[loops]; memset(stack, 0, loops); size_t stackptr = 0; |