aboutsummaryrefslogtreecommitdiff
path: root/better_string.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-09 12:04:19 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-09 12:04:19 -0800
commit0cfcbe979277f6d3b096b85d7fb6f4c02c366c72 (patch)
treebce0a91a88459050f9ba793796af440ec66b5c83 /better_string.c
parentdfe729c98b63d0f6c0041799a0fb46b2f476502e (diff)
fix invalid read/write of size 1; add framework for custom structs
Diffstat (limited to 'better_string.c')
-rw-r--r--better_string.c3
1 files changed, 2 insertions, 1 deletions
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;