all repos — hex @ b0dd9aefa24de4edf4e0c4c85ddde8c30acde412

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

Refactor memory allocation in hex_parse_quotation to use calloc for zero-initialization; enhances safety and prevents uninitialized memory usage.
h3rald h3rald@h3rald.com
Wed, 10 Sep 2025 17:50:06 +0200
commit

b0dd9aefa24de4edf4e0c4c85ddde8c30acde412

parent

b4de8aabfb2174b4bad4d1d0f563a2c5b89995ff

2 files changed, 12 insertions(+), 14 deletions(-)

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

@@ -1845,17 +1845,16 @@ else if (token->type == HEX_TOKEN_SYMBOL)

{ if (hex_valid_native_symbol(ctx, token->value)) { - item = malloc(sizeof(hex_item_t)); + item = calloc(1, sizeof(hex_item_t)); if (item) { - 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 (hex_get_symbol(ctx, token->value, value)) { - item->token = token; item->type = HEX_TYPE_NATIVE_SYMBOL; item->data.fn_value = value->data.fn_value; - free(value); // Free the temporary value holder + item->token = token; + free(value); // wrapper only } else {

@@ -1869,7 +1868,7 @@ }

} else { - item = malloc(sizeof(hex_item_t)); + item = calloc(1, sizeof(hex_item_t)); if (item) { item->type = HEX_TYPE_USER_SYMBOL;

@@ -1887,7 +1886,7 @@ }

} else if (token->type == HEX_TOKEN_QUOTATION_START) { - item = malloc(sizeof(hex_item_t)); + item = calloc(1, sizeof(hex_item_t)); if (item) { item->type = HEX_TYPE_QUOTATION;
M src/parser.csrc/parser.c

@@ -311,17 +311,16 @@ else if (token->type == HEX_TOKEN_SYMBOL)

{ if (hex_valid_native_symbol(ctx, token->value)) { - item = malloc(sizeof(hex_item_t)); + item = calloc(1, sizeof(hex_item_t)); if (item) { - 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 (hex_get_symbol(ctx, token->value, value)) { - item->token = token; item->type = HEX_TYPE_NATIVE_SYMBOL; item->data.fn_value = value->data.fn_value; - free(value); // Free the temporary value holder + item->token = token; + free(value); // wrapper only } else {

@@ -335,7 +334,7 @@ }

} else { - item = malloc(sizeof(hex_item_t)); + item = calloc(1, sizeof(hex_item_t)); if (item) { item->type = HEX_TYPE_USER_SYMBOL;

@@ -353,7 +352,7 @@ }

} else if (token->type == HEX_TOKEN_QUOTATION_START) { - item = malloc(sizeof(hex_item_t)); + item = calloc(1, sizeof(hex_item_t)); if (item) { item->type = HEX_TYPE_QUOTATION;