mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
xmalloc: calling xrealloc() or xreallocarray() with a 0-size is UB in C23
And likely to in future POSIX too.
This commit is contained in:
parent
ab4426f987
commit
f718cb3fb0
1 changed files with 4 additions and 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 *
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue