From 6a62f909d4bab90e65fbc679c82ef2b620d54e73 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 12 Jan 2022 01:57:49 +0100 Subject: [PATCH] Destroyed FFstrbufs can now be reused --- src/util/FFstrbuf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index bcf33d8d5..259bcf32a 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -31,6 +31,12 @@ void ffStrbufInitCopy(FFstrbuf* strbuf, const FFstrbuf* src) static void setCapacity(FFstrbuf* strbuf, uint32_t capacity) { + if(capacity == 0) + { + ffStrbufDestroy(strbuf); + return; + } + if(strbuf->allocated == 0) { strbuf->chars = malloc(sizeof(*strbuf->chars) * capacity); @@ -530,4 +536,5 @@ void ffStrbufDestroy(FFstrbuf* strbuf) { free(strbuf->chars); strbuf->allocated = 0; + strbuf->length = 0; }