diff options
author | Preston Pan <preston@nullring.xyz> | 2023-01-08 14:44:25 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-01-08 14:44:25 -0800 |
commit | 87d82ead963c24d84a4f6e417b96b9bf73d132bb (patch) | |
tree | 096e60118f6e62508db653d5102d85e77b8d73e9 /src/parser.c | |
parent | aa1dd020edb82f26dd5bc29378177cfcaa4c53ed (diff) |
fix memory problem
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/parser.c b/src/parser.c index 157bc4d..0f1ba69 100644 --- a/src/parser.c +++ b/src/parser.c @@ -30,6 +30,7 @@ parser_t *init_parser_copy_hash(lexer_t *lexer, hash_table_t *h) { p->tokens[size - 1] = t; if (t == NULL) break; + /* printf("%d: %s\n", t->type, t->value); */ } p->size = size; return p; @@ -185,7 +186,7 @@ ast_t *parse_include(parser_t *parser) { fseek(f, 0, SEEK_END); length = ftell(f); fseek(f, 0, SEEK_SET); - buffer = malloc(length); + buffer = malloc(length + 1); if (buffer) { fread(buffer, 1, length, f); } @@ -194,6 +195,7 @@ ast_t *parse_include(parser_t *parser) { parser_error(parser); } if (buffer) { + buffer[length] = '\0'; lexer_t *lexer = init_lexer(buffer); parser_t *p = init_parser_copy_hash(lexer, parser->symbol_table); ast_t *root = parse_all(p); |