Fixes.
h3rald h3rald@h3rald.com
Fri, 27 Dec 2024 17:08:47 +0100
3 files changed,
24 insertions(+),
20 deletions(-)
M
src/interpreter.c
→
src/interpreter.c
@@ -76,7 +76,6 @@ hex_item_t **quotation = quotationItem->data.quotation_value;
int quotation_size = quotationItem->quotation_size; result = hex_push_quotation(ctx, quotation, quotation_size); } - free(quotationItem); } if (result != 0)@@ -95,6 +94,5 @@ add_to_stack_trace(ctx, token);
print_stack_trace(ctx); return 1; } - hex_free_token(token); return 0; }
M
src/parser.c
→
src/parser.c
@@ -33,6 +33,7 @@ }
hex_token_t *token = (hex_token_t *)malloc(sizeof(hex_token_t)); token->value = NULL; + token->type = HEX_TOKEN_INVALID; token->position = (hex_file_position_t *)malloc(sizeof(hex_file_position_t)); token->position->line = position->line; token->position->column = position->column;@@ -184,12 +185,14 @@ }
else if (*ptr == '(') { token->type = HEX_TOKEN_QUOTATION_START; + token->value = strdup("("); ptr++; position->column++; } else if (*ptr == ')') { token->type = HEX_TOKEN_QUOTATION_END; + token->value = strdup(")"); ptr++; position->column++; }@@ -218,21 +221,19 @@ token->position->line = position->line;
token->position->column = position->column; } } - *input = ptr; return token; } int hex_valid_native_symbol(hex_context_t *ctx, const char *symbol) { - hex_doc_entry_t *doc = malloc(sizeof(hex_doc_entry_t *)); - for (size_t i = 0; i < HEX_NATIVE_SYMBOLS; i++) + hex_doc_entry_t *doc = malloc(sizeof(hex_doc_entry_t)); + if (hex_get_doc(ctx->docs, symbol, doc)) { - if (hex_get_doc(ctx->docs, symbol, doc)) - { - return 1; - } + free(doc); + return 1; } + free(doc); return 0; }@@ -358,6 +359,5 @@
result->type = HEX_TYPE_QUOTATION; result->data.quotation_value = quotation; result->quotation_size = size; - hex_free_token(token); return 0; }
M
src/stack.c
→
src/stack.c
@@ -311,18 +311,24 @@ {
copy->data.quotation_value = malloc(item->quotation_size * sizeof(hex_item_t *)); if (copy->data.quotation_value == NULL) { - free(copy); + HEX_FREE(ctx, copy); return NULL; } for (size_t i = 0; i < item->quotation_size; i++) { - copy->data.quotation_value[i] = hex_copy_item(ctx, item->data.quotation_value[i]); // Deep copy each item - if (copy->data.quotation_value[i] == NULL) + if (item->data.quotation_value[i] != NULL) { - hex_free_list(NULL, copy->data.quotation_value, i); - free(copy->data.quotation_value); - free(copy); - return NULL; + copy->data.quotation_value[i] = hex_copy_item(ctx, item->data.quotation_value[i]); // Deep copy each item + if (copy->data.quotation_value[i] == NULL) + { + hex_free_list(ctx, copy->data.quotation_value, i); + HEX_FREE(ctx, copy); + return NULL; + } + } + else + { + copy->data.quotation_value[i] = NULL; } } }@@ -336,7 +342,7 @@ {
copy->token = malloc(sizeof(hex_token_t)); if (copy->token == NULL) { - free(copy); + HEX_FREE(ctx, copy); return NULL; } *copy->token = *item->token; // Shallow copy the token structure@@ -345,8 +351,8 @@ {
copy->token->value = strdup(item->token->value); // Deep copy the token's value if (copy->token->value == NULL) { - free(copy->token); - free(copy); + hex_free_token(copy->token); + HEX_FREE(ctx, copy); return NULL; } }