Skip to content

Commit 6e0fb1e

Browse files
Make zero-sized new standards-compliant
This fixes part of arduino#287.
1 parent 66d06b0 commit 6e0fb1e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cores/arduino/new.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ namespace std {
2323
}
2424

2525
void * operator new(size_t size) {
26+
// Even zero-sized allocations should return a unique pointer, but
27+
// malloc does not guarantee this
28+
if (size == 0)
29+
size = 1;
2630
return malloc(size);
2731
}
2832
void * operator new[](size_t size) {

0 commit comments

Comments
 (0)