all repos — hex @ ac3a60095c5768fbc494b7659ae5768a176d92c9

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

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

ac3a60095c5768fbc494b7659ae5768a176d92c9

parent

4043ab03355e740b746ed24eedb108e8c2ffd23d

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

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

@@ -5265,7 +5265,7 @@ // This avoids aliasing between the original quotations and the new one.

if (list->type == HEX_TYPE_QUOTATION && value->type == HEX_TYPE_QUOTATION) { size_t new_size = list->quotation_size + value->quotation_size; - hex_item_t **items = (hex_item_t **)malloc(new_size * sizeof(hex_item_t *)); + hex_item_t **items = (hex_item_t **)calloc(new_size, sizeof(hex_item_t *)); if (!items) { hex_error(ctx, "[symbol cat] Memory allocation failed");

@@ -6533,7 +6533,7 @@ }

else { // Allocate result quotation (array of element pointers) - hex_item_t **quotation = (hex_item_t **)malloc(list->quotation_size * sizeof(hex_item_t *)); + hex_item_t **quotation = (hex_item_t **)calloc(list->quotation_size, sizeof(hex_item_t *)); if (!quotation) { hex_error(ctx, "[symbol map] Memory allocation failed");
M src/symbols.csrc/symbols.c

@@ -1338,7 +1338,7 @@ // This avoids aliasing between the original quotations and the new one.

if (list->type == HEX_TYPE_QUOTATION && value->type == HEX_TYPE_QUOTATION) { size_t new_size = list->quotation_size + value->quotation_size; - hex_item_t **items = (hex_item_t **)malloc(new_size * sizeof(hex_item_t *)); + hex_item_t **items = (hex_item_t **)calloc(new_size, sizeof(hex_item_t *)); if (!items) { hex_error(ctx, "[symbol cat] Memory allocation failed");

@@ -2606,7 +2606,7 @@ }

else { // Allocate result quotation (array of element pointers) - hex_item_t **quotation = (hex_item_t **)malloc(list->quotation_size * sizeof(hex_item_t *)); + hex_item_t **quotation = (hex_item_t **)calloc(list->quotation_size, sizeof(hex_item_t *)); if (!quotation) { hex_error(ctx, "[symbol map] Memory allocation failed");