aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/new.cpp
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2020-09-17 17:55:27 +0200
committerMatthijs Kooijman <matthijs@stdin.nl>2020-09-17 20:01:29 +0200
commit6e0fb1ee25efa07be5aef320501f3908f44e5b79 (patch)
treec0fa9de11ab6e29a02dfbd93676cbc58b0a7599a /cores/arduino/new.cpp
parent66d06b033c3f6eafde901418be3c089ffcc6ebfc (diff)
Make zero-sized new standards-compliant
This fixes part of #287.
Diffstat (limited to 'cores/arduino/new.cpp')
-rw-r--r--cores/arduino/new.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/cores/arduino/new.cpp b/cores/arduino/new.cpp
index a36fd21..1683594 100644
--- a/cores/arduino/new.cpp
+++ b/cores/arduino/new.cpp
@@ -23,6 +23,10 @@ namespace std {
}
void * operator new(size_t size) {
+ // Even zero-sized allocations should return a unique pointer, but
+ // malloc does not guarantee this
+ if (size == 0)
+ size = 1;
return malloc(size);
}
void * operator new[](size_t size) {