all repos — hex @ 054f1fb7b6b2f5ffc7924bfd3c5dd17208d4f62e

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

Refactor memory allocation in hex_push and hex_pop to use calloc for zero-initialization; enhances safety and prevents uninitialized memory usage.
h3rald h3rald@h3rald.com
Wed, 10 Sep 2025 18:03:11 +0200
commit

054f1fb7b6b2f5ffc7924bfd3c5dd17208d4f62e

parent

ac3a60095c5768fbc494b7659ae5768a176d92c9

2 files changed, 6 insertions(+), 6 deletions(-)

jump to
M src/hex.csrc/hex.c

@@ -479,7 +479,7 @@ int result = 0;

if (item->type == HEX_TYPE_USER_SYMBOL) { - hex_item_t *value = malloc(sizeof(hex_item_t)); + hex_item_t *value = calloc(1, sizeof(hex_item_t)); if (value == NULL) { hex_error(ctx, "[push] Failed to allocate memory for value");

@@ -519,7 +519,7 @@ }

} else if (item->type == HEX_TYPE_NATIVE_SYMBOL) { - hex_item_t *value = malloc(sizeof(hex_item_t)); + hex_item_t *value = calloc(1, sizeof(hex_item_t)); if (value == NULL) { hex_error(ctx, "[push] Failed to allocate memory for value");

@@ -675,7 +675,7 @@ {

if (ctx->stack->top < 0) { hex_error(ctx, "[pop] Insufficient items on the stack"); - hex_item_t *item = malloc(sizeof(hex_item_t)); + hex_item_t *item = calloc(1, sizeof(hex_item_t)); if (item) { item->type = HEX_TYPE_INVALID;
M src/stack.csrc/stack.c

@@ -47,7 +47,7 @@ int result = 0;

if (item->type == HEX_TYPE_USER_SYMBOL) { - hex_item_t *value = malloc(sizeof(hex_item_t)); + hex_item_t *value = calloc(1, sizeof(hex_item_t)); if (value == NULL) { hex_error(ctx, "[push] Failed to allocate memory for value");

@@ -87,7 +87,7 @@ }

} else if (item->type == HEX_TYPE_NATIVE_SYMBOL) { - hex_item_t *value = malloc(sizeof(hex_item_t)); + hex_item_t *value = calloc(1, sizeof(hex_item_t)); if (value == NULL) { hex_error(ctx, "[push] Failed to allocate memory for value");

@@ -243,7 +243,7 @@ {

if (ctx->stack->top < 0) { hex_error(ctx, "[pop] Insufficient items on the stack"); - hex_item_t *item = malloc(sizeof(hex_item_t)); + hex_item_t *item = calloc(1, sizeof(hex_item_t)); if (item) { item->type = HEX_TYPE_INVALID;