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
2 files changed,
6 insertions(+),
6 deletions(-)
M
src/hex.c
→
src/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.c
→
src/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;