Try allocating memory and zero it, and return NULL if failed. * '*usable' is set to the usable size if non NULL. */
| 157 | /* Try allocating memory and zero it, and return NULL if failed. |
| 158 | * '*usable' is set to the usable size if non NULL. */ |
| 159 | void *ztrycalloc_usable(size_t size, size_t *usable) { |
| 160 | ASSERT_NO_SIZE_OVERFLOW(size); |
| 161 | void *ptr = calloc(1, MALLOC_MIN_SIZE(size)+PREFIX_SIZE); |
| 162 | if (ptr == NULL) return NULL; |
| 163 | |
| 164 | #ifdef HAVE_MALLOC_SIZE |
| 165 | size = zmalloc_size(ptr); |
| 166 | update_zmalloc_stat_alloc(size); |
| 167 | if (usable) *usable = size; |
| 168 | return ptr; |
| 169 | #else |
| 170 | *((size_t*)ptr) = size; |
| 171 | update_zmalloc_stat_alloc(size+PREFIX_SIZE); |
| 172 | if (usable) *usable = size; |
| 173 | return (char*)ptr+PREFIX_SIZE; |
| 174 | #endif |
| 175 | } |
| 176 | |
| 177 | /* Allocate memory and zero it or panic */ |
| 178 | void *zcalloc(size_t size) { |
no test coverage detected