Fixes.
h3rald h3rald@h3rald.com
Sat, 28 Dec 2024 07:32:25 +0000
2 files changed,
9 insertions(+),
7 deletions(-)
M
src/error.c
→
src/error.c
@@ -98,7 +98,8 @@
for (size_t i = 0; i < ctx->stack_trace->size; i++) { int index = (ctx->stack_trace->start + ctx->stack_trace->size - 1 - i) % HEX_STACK_TRACE_SIZE; - hex_token_t token = *ctx->stack_trace->entries[index]; - fprintf(stderr, " %s (%s:%d:%d)\n", token.value, token.position->filename, token.position->line, token.position->column); + hex_token_t *token = malloc(sizeof(hex_token_t)); + token = ctx->stack_trace->entries[index]; + fprintf(stderr, " %s (%s:%d:%d)\n", token->value, token->position->filename, token->position->line, token->position->column); } }
M
src/stack.c
→
src/stack.c
@@ -207,16 +207,17 @@
// Pop function hex_item_t *hex_pop(hex_context_t *ctx) { - if (ctx->stack->top < 0) - { - hex_error(ctx, "[pop] Insufficient items on the stack"); - return NULL; - } hex_item_t *item = malloc(sizeof(hex_item_t)); if (item == NULL) { hex_error(ctx, "[pop] Failed to allocate memory for item"); return NULL; + } + if (ctx->stack->top < 0) + { + hex_error(ctx, "[pop] Insufficient items on the stack"); + item->type = HEX_TYPE_INVALID; + return item; } *item = *ctx->stack->entries[ctx->stack->top]; hex_debug_item(ctx, " POP", item);