Skip to content

Commit 037a052

Browse files
authored
[libc++] Handle 0 size case for testing support operator new (#93834)
The return of malloc is implementation defined when the requested size is 0. On platforms (such as AIX) that return a null pointer for 0 size, operator new will throw a bad_alloc exception. operator new should return a non null pointer for 0 size instead.
1 parent 6ef632a commit 037a052

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

libcxx/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
// void
1515
// inplace_merge(Iter first, Iter middle, Iter last);
1616

17-
// XFAIL: LIBCXX-AIX-FIXME
18-
1917
#include <algorithm>
2018
#include <cassert>
2119
#include <random>

libcxx/test/support/count_new.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ MemCounter &globalMemCounter = *getGlobalMemCounter();
385385
// operator new(size_t[, nothrow_t]) and operator delete(size_t[, nothrow_t])
386386
void* operator new(std::size_t s) TEST_THROW_SPEC(std::bad_alloc) {
387387
getGlobalMemCounter()->newCalled(s);
388+
if (s == 0)
389+
++s;
388390
void* p = std::malloc(s);
389391
if (p == nullptr)
390392
detail::throw_bad_alloc_helper();
@@ -417,6 +419,8 @@ void operator delete(void* p, std::nothrow_t const&) TEST_NOEXCEPT {
417419
// operator new[](size_t[, nothrow_t]) and operator delete[](size_t[, nothrow_t])
418420
void* operator new[](std::size_t s) TEST_THROW_SPEC(std::bad_alloc) {
419421
getGlobalMemCounter()->newArrayCalled(s);
422+
if (s == 0)
423+
s++;
420424
void* p = std::malloc(s);
421425
if (p == nullptr)
422426
detail::throw_bad_alloc_helper();

0 commit comments

Comments
 (0)