mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
xmalloc: fix edge case handling in xcalloc() function
This commit is contained in:
parent
139f59c27d
commit
fe9eaf3aaf
1 changed files with 3 additions and 4 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
@ -36,10 +37,8 @@ xmalloc(size_t size)
|
||||||
void *
|
void *
|
||||||
xcalloc(size_t nmemb, size_t size)
|
xcalloc(size_t nmemb, size_t size)
|
||||||
{
|
{
|
||||||
if (unlikely(nmemb == 0 || size == 0)) {
|
assert(size != 0);
|
||||||
size = 1;
|
return check_alloc(calloc(likely(nmemb) ? nmemb : 1, size));
|
||||||
}
|
|
||||||
return check_alloc(calloc(nmemb, size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue