version 1.1, 2007/05/29 18:24:56 |
version 1.2, 2009/06/07 08:39:13 |
|
|
} |
} |
|
|
void * |
void * |
|
xcalloc(size_t nmemb, size_t size) |
|
{ |
|
void *ptr; |
|
|
|
if (size == 0 || nmemb == 0) |
|
errx(1, "xcalloc: zero size"); |
|
if (SIZE_MAX / nmemb < size) |
|
errx(1, "xcalloc: nmemb * size > SIZE_MAX"); |
|
ptr = calloc(nmemb, size); |
|
if (ptr == NULL) |
|
errx(1, "xcalloc: out of memory (allocating %lu bytes)", |
|
(u_long)(size * nmemb)); |
|
return ptr; |
|
} |
|
|
|
void * |
xrealloc(void *ptr, size_t nmemb, size_t size) |
xrealloc(void *ptr, size_t nmemb, size_t size) |
{ |
{ |
void *new_ptr; |
void *new_ptr; |
|
|
|
|
if (new_size == 0) |
if (new_size == 0) |
errx(2, NULL); |
errx(2, NULL); |
if (SIZE_T_MAX / nmemb < size) |
if (SIZE_MAX / nmemb < size) |
errx(2, NULL); |
errx(2, NULL); |
if (ptr == NULL) |
if (ptr == NULL) |
new_ptr = malloc(new_size); |
new_ptr = malloc(new_size); |