all repos — hex @ 14b27e19ad074989551b6027f87b0cf64384c161

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

Removed reference to strndup.
h3rald h3rald@h3rald.com
Sun, 08 Dec 2024 17:43:17 +0100
commit

14b27e19ad074989551b6027f87b0cf64384c161

parent

87e62fb06e564cee7fdc1916b5e623f198ec125b

1 files changed, 9 insertions(+), 1 deletions(-)

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

@@ -2646,7 +2646,15 @@ result = 1;

break; } quotation[i]->type = HEX_TYPE_STRING; - quotation[i]->data.str_value = strndup(&str.data.str_value[i], 1); + quotation[i]->data.str_value = (char *)malloc(2); // Allocate 2 bytes: 1 for the character and 1 for null terminator + if (!quotation[i]->data.str_value) + { + hex_error(ctx, "Memory allocation failed"); + result = 1; + break; + } + quotation[i]->data.str_value[0] = str.data.str_value[i]; // Copy the single character + quotation[i]->data.str_value[1] = '\0'; // Null-terminate the string } if (result == 0) {