From 1cf817eba1ab8c2ee46a73c6bea9b7e70e418cdd Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Tue, 13 Aug 2024 11:08:28 +0200 Subject: Add `cpyval` function --- properties.y | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/properties.y b/properties.y index 0f8c8d4..7bdd864 100644 --- a/properties.y +++ b/properties.y @@ -4,6 +4,15 @@ #include #include "utils/string.h" +char * +cpyval(size_t number, + size_t size, + char *value) +{ + char *dest = calloc(number, size); + return strcat(dest, value); +} + %} %token KEY DIV VALUE @@ -28,8 +37,7 @@ property: KEY DIV value { ; value: VALUE { - $$.value = calloc(2, sizeof(char)); - strcat($$.value, $1.value); + $$.value = cpyval(2, sizeof(char), $1.value); } | value VALUE { char *s = strdup($$.value); -- cgit v1.2.3