all repos — hex @ 4043ab03355e740b746ed24eedb108e8c2ffd23d

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

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

4043ab03355e740b746ed24eedb108e8c2ffd23d

parent

0c8622cff8de5b10a8d6ca8401da3e8d0e4747d4

3 files changed, 16 insertions(+), 6 deletions(-)

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

@@ -1010,7 +1010,7 @@ }

hex_registry_t *hex_registry_create() { - hex_registry_t *registry = malloc(sizeof(hex_registry_t)); + hex_registry_t *registry = calloc(1, sizeof(hex_registry_t)); if (registry == NULL) { return NULL;

@@ -1179,7 +1179,7 @@ entry = entry->next;

} // Add a new entry to the bucket - hex_registry_entry_t *new_entry = malloc(sizeof(hex_registry_entry_t)); + hex_registry_entry_t *new_entry = calloc(1, sizeof(hex_registry_entry_t)); if (new_entry == NULL) { return 1; // Memory allocation failed

@@ -5635,7 +5635,12 @@ if (size >= capacity)

{ capacity *= 2; hex_item_t **tmp = (hex_item_t **)realloc(quotation, capacity * sizeof(hex_item_t *)); - if (!tmp) { hex_error(ctx, "[symbol split] Memory allocation failed"); result = 1; break; } + if (!tmp) + { + hex_error(ctx, "[symbol split] Memory allocation failed"); + result = 1; + break; + } quotation = tmp; if (!quotation) {
M src/registry.csrc/registry.c

@@ -32,7 +32,7 @@ }

hex_registry_t *hex_registry_create() { - hex_registry_t *registry = malloc(sizeof(hex_registry_t)); + hex_registry_t *registry = calloc(1, sizeof(hex_registry_t)); if (registry == NULL) { return NULL;

@@ -201,7 +201,7 @@ entry = entry->next;

} // Add a new entry to the bucket - hex_registry_entry_t *new_entry = malloc(sizeof(hex_registry_entry_t)); + hex_registry_entry_t *new_entry = calloc(1, sizeof(hex_registry_entry_t)); if (new_entry == NULL) { return 1; // Memory allocation failed
M src/symbols.csrc/symbols.c

@@ -1708,7 +1708,12 @@ if (size >= capacity)

{ capacity *= 2; hex_item_t **tmp = (hex_item_t **)realloc(quotation, capacity * sizeof(hex_item_t *)); - if (!tmp) { hex_error(ctx, "[symbol split] Memory allocation failed"); result = 1; break; } + if (!tmp) + { + hex_error(ctx, "[symbol split] Memory allocation failed"); + result = 1; + break; + } quotation = tmp; if (!quotation) {