Add nullptr support to sized delete operators.

This commit is contained in:
Jason Evans 2017-01-13 18:43:21 -08:00
parent 41aa41853c
commit 8115f05b26
2 changed files with 16 additions and 0 deletions

View File

@ -118,11 +118,17 @@ void operator delete[](void *ptr, const std::nothrow_t &) noexcept
void
operator delete(void *ptr, std::size_t size) noexcept
{
if (unlikely(ptr == nullptr)) {
return;
}
je_sdallocx(ptr, size, /*flags=*/0);
}
void operator delete[](void *ptr, std::size_t size) noexcept
{
if (unlikely(ptr == nullptr)) {
return;
}
je_sdallocx(ptr, size, /*flags=*/0);
}

View File

@ -6,6 +6,16 @@ TEST_BEGIN(test_basic)
auto foo = new long(4);
assert_ptr_not_null(foo, "Unexpected new[] failure");
delete foo;
// Test nullptr handling.
foo = nullptr;
delete foo;
auto bar = new long;
assert_ptr_not_null(bar, "Unexpected new failure");
delete bar;
// Test nullptr handling.
bar = nullptr;
delete bar;
}
TEST_END