From: Michael Göhler Date: Sun, 21 Sep 2014 10:23:35 +0000 (+0200) Subject: fixed segv in cstring.c, closes #18 X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=18118c25abc51e71df1cdc1ffca75fda1cd92173;p=smdp.git fixed segv in cstring.c, closes #18 --- 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) {