diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2025-02-03 07:31:31 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2025-02-05 12:35:17 +0000 |
| commit | f718cb3fb0d627cab8d952b94891e38238934090 (patch) | |
| tree | da25ca9fc5c946a76d992755cb2772f00061b222 /xmalloc.c | |
| parent | url-mode: regex: make sure there's always room for the NULL terminator (diff) | |
xmalloc: calling xrealloc() or xreallocarray() with a 0-size is UB in C23
And likely to in future POSIX too.
Diffstat (limited to 'xmalloc.c')
| -rw-r--r-- | xmalloc.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -32,15 +32,17 @@ xcalloc(size_t nmemb, size_t size) void * xrealloc(void *ptr, size_t size) { + xassert(size != 0); void *alloc = realloc(ptr, size); - return unlikely(size == 0) ? alloc : check_alloc(alloc); + return check_alloc(alloc); } void * xreallocarray(void *ptr, size_t n, size_t size) { + xassert(n != 0 && size != 0); void *alloc = reallocarray(ptr, n, size); - return unlikely(size == 0) ? alloc : check_alloc(alloc); + return check_alloc(alloc); } char * |
