From a8fb272bfd44cc0cbb70b73731e9f2cea8355f62 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 1 Oct 2025 00:53:08 +0200 Subject: [PATCH] Fix realloc with size == 0 in dbuf_default_realloc() If the new_size argument to realloc is zero, the behavior is undefined since C23. --- cutils.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cutils.c b/cutils.c index b41eda355..7d36ddfdb 100644 --- a/cutils.c +++ b/cutils.c @@ -102,6 +102,10 @@ int js__has_suffix(const char *str, const char *suffix) static void *dbuf_default_realloc(void *opaque, void *ptr, size_t size) { + if (unlikely(size == 0)) { + free(ptr); + return NULL; + } return realloc(ptr, size); }