From 18118c25abc51e71df1cdc1ffca75fda1cd92173 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michael=20G=C3=B6hler?= Date: Sun, 21 Sep 2014 12:23:35 +0200 Subject: [PATCH] fixed segv in cstring.c, closes #18 --- cstring.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cstring.c b/cstring.c index 3eed860..958062b 100644 --- a/cstring.c +++ b/cstring.c @@ -47,11 +47,12 @@ void cstring_expand(cstring_t *self, char x) { void cstring_expand_arr(cstring_t *self, char *x) { if(self->size + strlen(x) + sizeof(char) > self->alloc) { - self->alloc += (REALLOC_ADD * sizeof(char)); + self->alloc = ((strlen(x) + self->size + 1) * sizeof(char)); self->text = realloc(self->text, self->alloc); } self->text = strcat(self->text, x); self->size = strlen(self->text); + self->text[self->size+1] = '\0'; } void cstring_reset(cstring_t *self) { -- 2.20.1