Improved string handling.
h3rald h3rald@h3rald.com
Wed, 20 Nov 2024 16:58:56 +0100
1 files changed,
9 insertions(+),
3 deletions(-)
jump to
M
hex.c
→
hex.c
@@ -289,14 +289,14 @@ HEX_StackElement element = {.type = HEX_TYPE_INTEGER, .data.intValue = value};
return hex_push(element); } -int hex_push_string(const char *value) +char *hex_process_string(const char *value) { size_t len = strlen(value); char *processedStr = (char *)malloc(len + 1); if (!processedStr) { hex_error("Memory allocation failed"); - return 1; + return (char *)value; } char *dst = processedStr;@@ -345,7 +345,12 @@ }
src++; } *dst = '\0'; + return processedStr; +} +int hex_push_string(const char *value) +{ + char *processedStr = hex_process_string(value); HEX_StackElement element = {.type = HEX_TYPE_STRING, .data.strValue = processedStr}; return hex_push(element); }@@ -717,8 +722,9 @@ element->data.intValue = (int)strtol(token->value, NULL, 16);
} else if (token->type == HEX_TOKEN_STRING) { + char *processedStr = hex_process_string(token->value); element->type = HEX_TYPE_STRING; - element->data.strValue = strdup(token->value); + element->data.strValue = strdup(processedStr); } else if (token->type == HEX_TOKEN_SYMBOL) {