all repos — hex @ b1891ccee6a3403d350d0721dc7b47acebe2aaa1

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

Fixes.
h3rald h3rald@h3rald.com
Sat, 28 Dec 2024 07:32:25 +0000
commit

b1891ccee6a3403d350d0721dc7b47acebe2aaa1

parent

7702b7d229d6d5f69d7dff3c0baa7773350fa075

2 files changed, 9 insertions(+), 7 deletions(-)

jump to
M src/error.csrc/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.csrc/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);