| 275 | reallocarray(void* ptr, size_t count, size_t size); |
| 276 | |
| 277 | extern void* RPMALLOC_CDECL |
| 278 | reallocarray(void* ptr, size_t count, size_t size) { |
| 279 | size_t total; |
| 280 | #if ENABLE_VALIDATE_ARGS |
| 281 | #ifdef _MSC_VER |
| 282 | int err = SizeTMult(count, size, &total); |
| 283 | if ((err != S_OK) || (total >= MAX_ALLOC_SIZE)) { |
| 284 | errno = EINVAL; |
| 285 | return 0; |
| 286 | } |
| 287 | #else |
| 288 | int err = __builtin_umull_overflow(count, size, &total); |
| 289 | if (err || (total >= MAX_ALLOC_SIZE)) { |
| 290 | errno = EINVAL; |
| 291 | return 0; |
| 292 | } |
| 293 | #endif |
| 294 | #else |
| 295 | total = count * size; |
| 296 | #endif |
| 297 | return realloc(ptr, total); |
| 298 | } |
| 299 | |
| 300 | extern inline void* RPMALLOC_CDECL |
| 301 | valloc(size_t size) { |