X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=cstring.c;h=958062bfe8c0b9d2287f56e6911e1dc1a4f7588e;hb=18118c25abc51e71df1cdc1ffca75fda1cd92173;hp=3eed8604c307ab6ecdc94da2de6c031a8f993aef;hpb=d2f91e2e0fafdac20b910ba76516dff72ac467b1;p=smdp.git 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) {