From 1e8cbf03aa2e1c2f4da500b30445d68c5b6a6cfd Mon Sep 17 00:00:00 2001 From: frapank Date: Mon, 22 Jun 2026 23:43:15 +0200 Subject: [PATCH 1/3] fix: dstrfree don't use the custom DSTR_FREE() call --- dstr.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dstr.c b/dstr.c index 0598732..1c67292 100644 --- a/dstr.c +++ b/dstr.c @@ -542,19 +542,19 @@ void dstrfree(dstr s) switch (t) { case DSTRHD_TYPE_8: { - free(DSTRGETHDR(8, s)); + DSTR_FREE(DSTRGETHDR(8, s)); return; } case DSTRHD_TYPE_16: { - free(DSTRGETHDR(16, s)); + DSTR_FREE(DSTRGETHDR(16, s)); return; } case DSTRHD_TYPE_32: { - free(DSTRGETHDR(32, s)); + DSTR_FREE(DSTRGETHDR(32, s)); return; } case DSTRHD_TYPE_64: { - free(DSTRGETHDR(64, s)); + DSTR_FREE(DSTRGETHDR(64, s)); return; } } From ac7c3b317e2ff614a2f3bb241fdaebf97d46a9bb Mon Sep 17 00:00:00 2001 From: frapank Date: Mon, 22 Jun 2026 23:46:28 +0200 Subject: [PATCH 2/3] fix: buffer overflow in dstrnew_custom() if msg="" and cap=0 is passed --- dstr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dstr.c b/dstr.c index 1c67292..4ee84c6 100644 --- a/dstr.c +++ b/dstr.c @@ -526,7 +526,7 @@ dstr dstrnew_custom(const char* msg, size_t cap) if (!msg) return NULL; size_t s_len = strlen(msg); - size_t alloc_size = (s_len > cap) ? (s_len + 1) : cap; + size_t alloc_size = (s_len + 1 > cap) ? (s_len + 1) : cap; enum dstrhd_type t = _dstr_type_by_size(alloc_size); From 42ffeac697b09cf235edbfe9ddbc1972430d1fca Mon Sep 17 00:00:00 2001 From: frapank Date: Mon, 22 Jun 2026 23:50:03 +0200 Subject: [PATCH 3/3] fix: inconsistency in dstrfree() --- dstr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dstr.c b/dstr.c index 4ee84c6..b83f7e1 100644 --- a/dstr.c +++ b/dstr.c @@ -538,7 +538,7 @@ void dstrfree(dstr s) { if (!s) return; - enum dstrhd_type t = s[-1]; + enum dstrhd_type t = DSTRGETTYPE(s); switch (t) { case DSTRHD_TYPE_8: {