MCPcopy Create free account
hub / github.com/adny-code/fastgrind / __wrap_reallocarray

Function __wrap_reallocarray

include/fastgrind.h:2406–2473  ·  view source on GitHub ↗

glibc function

Source from the content-addressed store, hash-verified

2404
2405 // glibc function
2406 MEM_NO_INSTRUMENT MEM_INLINE_USED inline void *__wrap_reallocarray(void *ptr, size_t nmemb, size_t size)
2407 {
2408 size_t total = 0;
2409 #if defined(__GNUC__)
2410 if (__builtin_mul_overflow(nmemb, size, &total))
2411 {
2412 errno = ENOMEM;
2413 return NULL;
2414 }
2415 #else
2416 if (size != 0 && nmemb > static_cast<size_t>(-1) / size)
2417 {
2418 errno = ENOMEM;
2419 return NULL;
2420 }
2421 total = nmemb * size;
2422 #endif
2423
2424 if (__mem_in_probe_)
2425 {
2426 #if defined(FASTGRIND_TC_MALLOC)
2427 return tc_realloc(ptr, total);
2428 #elif defined(FASTGRIND_JE_MALLOC)
2429 return realloc(ptr, total);
2430 #else
2431 return __real_realloc(ptr, total);
2432 #endif
2433 }
2434
2435 __mem_in_probe_ = true;
2436
2437 size_t old_size = ptr ? malloc_usable_size(ptr) : 0;
2438
2439 if (total == 0 && ptr)
2440 {
2441 if (old_size)
2442 memLocalInfo::instance().sub(old_size);
2443
2444 #if defined(FASTGRIND_TC_MALLOC)
2445 tc_free(ptr);
2446 #elif defined(FASTGRIND_JE_MALLOC)
2447 je_free_default(ptr);
2448 #else
2449 __real_free(ptr);
2450 #endif
2451 __mem_in_probe_ = false;
2452 return nullptr;
2453 }
2454
2455 void *p = nullptr;
2456 #if defined(FASTGRIND_TC_MALLOC)
2457 p = tc_realloc(ptr, total);
2458 #elif defined(FASTGRIND_JE_MALLOC)
2459 p = realloc(ptr, total);
2460 #else
2461 p = __real_realloc(ptr, total);
2462 #endif
2463

Callers

nothing calls this directly

Calls 2

subMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected