From 0cfcbe979277f6d3b096b85d7fb6f4c02c366c72 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Tue, 9 Jan 2024 12:04:19 -0800 Subject: fix invalid read/write of size 1; add framework for custom structs --- better_string.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'better_string.c') diff --git a/better_string.c b/better_string.c index b3bc931..e601586 100644 --- a/better_string.c +++ b/better_string.c @@ -9,9 +9,10 @@ string_t *init_string(char *s) { die("malloc in init_string"); /* If we pass in NULL we assume that we want to append things to this in the * future */ - if (s == NULL) { + if (s == NULL || strcmp(s, "") == 0) { str->bufsize = 10; str->value = calloc(str->bufsize, sizeof(char)); + str->value[0] = '\0'; if (str->value == NULL) die("calloc in init_string"); str->length = 0; -- cgit