Skip to content

Commit 7471928

Browse files
Make zero-sized new standards-compliant
This fixes part of arduino#287.
1 parent af3f085 commit 7471928

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Diff for: cores/arduino/new.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "new.h"
2020

2121
void * operator new(size_t size) {
22+
// Even zero-sized allocations should return a unique pointer, but
23+
// malloc does not guarantee this
24+
if (size == 0)
25+
size = 1;
2226
return malloc(size);
2327
}
2428
void * operator new[](size_t size) {

0 commit comments

Comments
 (0)