Try allocating memory and zero it, and return NULL if failed. * '*usable' is set to the usable size if non NULL. */
| 169 | /* Try allocating memory and zero it, and return NULL if failed. |
| 170 | * '*usable' is set to the usable size if non NULL. */ |
| 171 | void *ztrycalloc_usable(size_t size, size_t *usable) { |
| 172 | ASSERT_NO_SIZE_OVERFLOW(size); |
| 173 | void *ptr = calloc(1, MALLOC_MIN_SIZE(size)+PREFIX_SIZE, MALLOC_LOCAL); |
| 174 | if (ptr == NULL) return NULL; |
| 175 | |
| 176 | #ifdef HAVE_MALLOC_SIZE |
| 177 | size = zmalloc_size(ptr); |
| 178 | update_zmalloc_stat_alloc(size); |
| 179 | if (usable) *usable = size; |
| 180 | return ptr; |
| 181 | #else |
| 182 | *((size_t*)ptr) = size; |
| 183 | update_zmalloc_stat_alloc(size+PREFIX_SIZE); |
| 184 | if (usable) *usable = size; |
| 185 | return (char*)ptr+PREFIX_SIZE; |
| 186 | #endif |
| 187 | } |
| 188 | |
| 189 | /* Allocate memory and zero it or panic */ |
| 190 | void *zcalloc(size_t size, enum MALLOC_CLASS /*mclass*/) { |
no test coverage detected