From 1a1a8880dda3c85a7e4e61b63b94f98dd765673d Mon Sep 17 00:00:00 2001 From: manolipt Date: Mon, 8 May 2023 19:01:20 -0700 Subject: [PATCH] [utils] Re-implement safe fail behavior into AllocatorBase When pulling from upstream develop, AllocatorBase has been moved to utils/allocator.hpp. This commit simply re-introduces safe fail behavior into AllocatorBase.construct and AllocatorBase.destroy that was previously added by Matthew Arnold (see 3ed0768 for more details). --- src/modm/utils/allocator.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modm/utils/allocator.hpp b/src/modm/utils/allocator.hpp index 880220a3e4..28f600414d 100644 --- a/src/modm/utils/allocator.hpp +++ b/src/modm/utils/allocator.hpp @@ -42,6 +42,7 @@ class AllocatorBase static inline void construct(T* p, const T& value) { + if (p == nullptr) return; // placement new ::new((void *) p) T(value); } @@ -57,6 +58,7 @@ class AllocatorBase static inline void destroy(T* p) { + if (p == nullptr) return; p->~T(); }