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 *
|
void *
|
||||||
xrealloc(void *ptr, size_t size)
|
xrealloc(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
|
xassert(size != 0);
|
||||||
void *alloc = realloc(ptr, size);
|
void *alloc = realloc(ptr, size);
|
||||||
return unlikely(size == 0) ? alloc : check_alloc(alloc);
|
return check_alloc(alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
xreallocarray(void *ptr, size_t n, size_t size)
|
xreallocarray(void *ptr, size_t n, size_t size)
|
||||||
{
|
{
|
||||||
|
xassert(n != 0 && size != 0);
|
||||||
void *alloc = reallocarray(ptr, n, size);
|
void *alloc = reallocarray(ptr, n, size);
|
||||||
return unlikely(size == 0) ? alloc : check_alloc(alloc);
|
return check_alloc(alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue