version 1.2, 2015/06/17 18:51:11 |
version 1.3, 2015/11/17 18:25:03 |
|
|
errx(1, "xmalloc: zero size"); |
errx(1, "xmalloc: zero size"); |
ptr = malloc(size); |
ptr = malloc(size); |
if (ptr == NULL) |
if (ptr == NULL) |
errx(1, |
err(1, "xmalloc: allocating %zu bytes", size); |
"xmalloc: out of memory (allocating %zu bytes)", |
|
size); |
|
return ptr; |
return ptr; |
} |
} |
|
|
|
|
|
|
if (size == 0 || nmemb == 0) |
if (size == 0 || nmemb == 0) |
errx(1, "xcalloc: zero size"); |
errx(1, "xcalloc: zero size"); |
if (SIZE_MAX / nmemb < size) |
|
errx(1, "xcalloc: nmemb * size > SIZE_MAX"); |
|
ptr = calloc(nmemb, size); |
ptr = calloc(nmemb, size); |
if (ptr == NULL) |
if (ptr == NULL) |
errx(1, "xcalloc: out of memory (allocating %zu bytes)", |
err(1, "xcalloc: allocating %zu * %zu bytes", nmemb, size); |
(size * nmemb)); |
|
return ptr; |
return ptr; |
} |
} |
|
|
|
|
|
|
new_ptr = reallocarray(ptr, nmemb, size); |
new_ptr = reallocarray(ptr, nmemb, size); |
if (new_ptr == NULL) |
if (new_ptr == NULL) |
errx(1, "xreallocarray: out of memory (new_size %zu bytes)", |
err(1, "xreallocarray: allocating %zu * %zu bytes", |
nmemb * size); |
nmemb, size); |
return new_ptr; |
return new_ptr; |
} |
} |
|
|
|
|
va_end(ap); |
va_end(ap); |
|
|
if (i < 0 || *ret == NULL) |
if (i < 0 || *ret == NULL) |
errx(1, "xasprintf: could not allocate memory"); |
err(1, "xasprintf"); |
|
|
return (i); |
return i; |
} |
} |