diff --git a/src/strbuffer.c b/src/strbuffer.c index 6674f49..c6d412f 100644 --- a/src/strbuffer.c +++ b/src/strbuffer.c @@ -16,7 +16,8 @@ int strbuffer_init(strbuffer_t *strbuff) if(!strbuff->value) return -1; - memset(strbuff->value, 0, strbuff->size); + /* initialize to empty */ + strbuff->value[0] = '\0'; return 0; } @@ -55,13 +56,11 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size) strbuff->value = realloc(strbuff->value, strbuff->size); if(!strbuff->value) return -1; - - memset(strbuff->value + strbuff->length + size, 0, - strbuff->size - strbuff->length - size); } memcpy(strbuff->value + strbuff->length, data, size); strbuff->length += size; + strbuff->value[strbuff->length] = '\0'; return 0; } diff --git a/src/strbuffer.h b/src/strbuffer.h index f5344b8..c77be3c 100644 --- a/src/strbuffer.h +++ b/src/strbuffer.h @@ -3,8 +3,8 @@ typedef struct { char *value; - int length; - int size; + int length; /* bytes used */ + int size; /* bytes allocated */ } strbuffer_t; int strbuffer_init(strbuffer_t *strbuff);