From 2f9dfb38ca7393e70553c2babf65bdde5f554a6f Mon Sep 17 00:00:00 2001 From: Charlie Gordon Date: Mon, 9 Dec 2024 03:09:05 +0100 Subject: [PATCH] Fix ASAN crash bug: allocate extra byte for null terminator in `dbuf_str` --- cutils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cutils.h b/cutils.h index da81e15..7adc68f 100644 --- a/cutils.h +++ b/cutils.h @@ -792,9 +792,9 @@ static inline const char *dbuf_str(DynBuf *s) { @note: a null terminator is set at the end of the buffer and an empty string is returned if the buffer has not been allocated. */ - if (s->size == 0) + if (s->size == 0 || dbuf_putc(s, '\0')) return ""; - s->buf[s->size] = '\0'; + s->size--; return cs8(s->buf); }