From 6e0fb1ee25efa07be5aef320501f3908f44e5b79 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 17 Sep 2020 17:55:27 +0200 Subject: Make zero-sized new standards-compliant This fixes part of #287. --- cores/arduino/new.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cores') 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) { -- cgit v1.2.3-18-g5258