From fe7eaa8de3ea7d3c856fa0276c0f5bc4305d9aec Mon Sep 17 00:00:00 2001 From: Ugric Date: Wed, 9 Jul 2025 14:47:16 +0100 Subject: [PATCH] fix some memory leaks --- src/err.c | 15 +++++++-------- src/main.c | 2 +- src/parser/parser.c | 5 +++-- testing.ar | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/err.c b/src/err.c index 72ba599..a46dd3e 100644 --- a/src/err.c +++ b/src/err.c @@ -92,21 +92,20 @@ void output_err(ArErr err) { getline(&buffer, &size, file); char *line_starts = buffer; - char line_column = err.column; - while (*line_starts && isspace((unsigned char)*line_starts) && line_starts-buffer < err.column) { + while (*line_starts && isspace((unsigned char)*line_starts) && line_starts-buffer < err.column-1) { line_starts++; - line_column--; + err.column--; } fprintf(stderr, " %zu | ", err.line); if (err.length) { - fprintf(stderr, "%.*s", (int)line_column - 1, line_starts); + fprintf(stderr, "%.*s", (int)err.column-1, line_starts); dyefg(stderr, DYE_RED); dye_style(stderr, DYE_STYLE_BOLD); - fprintf(stderr, "%.*s", err.length, line_starts + line_column - 1); + fprintf(stderr, "%.*s", err.length, line_starts + err.column - 1); dye_style(stderr, DYE_STYLE_RESET); dyefg(stderr, DYE_RESET); - fprintf(stderr, "%s", line_starts + (int)line_column + err.length - 1); - for (int64_t i = 0; i < line_column - 1; i++) { + fprintf(stderr, "%s", line_starts + (int)err.column + err.length - 1); + for (int64_t i = 0; i < err.column - 1; i++) { fprintf(stderr, " "); } } else { @@ -119,7 +118,7 @@ void output_err(ArErr err) { } fprintf(stderr, "| "); - for (int i = 1; i < line_column; i++) { + for (int i = 1; i < err.column; i++) { fprintf(stderr, " "); } dyefg(stderr, DYE_RED); diff --git a/src/main.c b/src/main.c index 5256b24..d808e69 100644 --- a/src/main.c +++ b/src/main.c @@ -291,7 +291,7 @@ Execution execute(char *absolute_path) { RuntimeState state = init_runtime_state(translated); Stack main_scope = create_scope(NULL); ArErr err = runtime(translated, state, main_scope); - + free(state.registers); end = clock(); time_spent = (double)(end - start) / CLOCKS_PER_SEC; total_time_spent += time_spent; diff --git a/src/parser/parser.c b/src/parser/parser.c index a52e42d..aaba98c 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -88,12 +88,13 @@ ParsedValueReturn parse_token_full(char *file, DArray *tokens, size_t *index, case TOKEN_NEW_LINE: (*index)++; return (ParsedValueReturn){no_err, NULL}; - case TOKEN_INDENT: + case TOKEN_INDENT:; + Token *token_indent = token; if (strlen(token->value) > 0 && (*index + 1) < tokens->size) { token = darray_get(tokens, (*index) + 1); if (token->type != TOKEN_NEW_LINE) { return (ParsedValueReturn){ - create_err(token->line, token->column, token->length, file, + create_err(token_indent->line, token_indent->column, token_indent->length, file, "Syntax Error", "unexpected indent"), NULL}; } diff --git a/testing.ar b/testing.ar index 1eeac2b..04f8b72 100644 --- a/testing.ar +++ b/testing.ar @@ -1 +1 @@ - term.log("hello world") \ No newline at end of file +let x = 10 \ No newline at end of file