1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-16 00:43:00 +03:00

overwrite weak new (std::nothrow) calls

This commit is contained in:
david gauchard
2020-08-24 22:42:29 +02:00
parent 2b6423edcc
commit c111713208

View File

@ -36,28 +36,44 @@ extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
// overwrite weak operators new/new[] definitions
void *operator new(size_t size)
void* operator new(size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
#if defined(NEW_OOM_ABORT)
__unhandled_exception(PSTR("OOM"));
#endif
}
return ret;
return ret;
}
void *operator new[](size_t size)
void* operator new[](size_t size)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
#if defined(NEW_OOM_ABORT)
__unhandled_exception(PSTR("OOM"));
#endif
}
return ret;
}
void* operator new (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}
void* operator new[] (size_t size, const std::nothrow_t&)
{
void *ret = malloc(size);
if (0 != size && 0 == ret) {
umm_last_fail_alloc_addr = __builtin_return_address(0);
umm_last_fail_alloc_size = size;
}
return ret;
}