Skip to content

Commit 20b25df

Browse files
mikmasaghul
authored andcommitted
Fix realloc with size == 0 in dbuf_default_realloc()
If the new_size argument to realloc is zero, the behavior is undefined since C23.
1 parent 08db51a commit 20b25df

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cutils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ int js__has_suffix(const char *str, const char *suffix)
102102

103103
static void *dbuf_default_realloc(void *opaque, void *ptr, size_t size)
104104
{
105+
if (unlikely(size == 0)) {
106+
free(ptr);
107+
return NULL;
108+
}
105109
return realloc(ptr, size);
106110
}
107111

0 commit comments

Comments
 (0)