From b421ba5b69a976e97fd7dfffe93c65d8d2b3ffc3 Mon Sep 17 00:00:00 2001 From: Jonathan Protzenko Date: Wed, 4 Nov 2015 15:43:36 -0800 Subject: [PATCH] A new check for -> on ManagedTypes. --- inc/ErrorNo.h | 5 ++++- inc/ManagedType.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/inc/ErrorNo.h b/inc/ErrorNo.h index 100c9a3..2c92312 100644 --- a/inc/ErrorNo.h +++ b/inc/ErrorNo.h @@ -45,6 +45,9 @@ enum PanicCode{ MICROBIT_OOM = 20, // Corruption detected in the micro:bit heap space - MICROBIT_HEAP_ERROR = 30 + MICROBIT_HEAP_ERROR = 30, + + // Dereference of a NULL pointer through the ManagedType class, + MICROBIT_NULL_DEREFERENCE = 40, }; #endif diff --git a/inc/ManagedType.h b/inc/ManagedType.h index 9fbda48..4f11786 100644 --- a/inc/ManagedType.h +++ b/inc/ManagedType.h @@ -103,6 +103,8 @@ public: * x->m(); // resolves to T::m */ T* operator->() { + if (object == NULL) + panic(MICROBIT_NULL_DEREFERENCE); return object; }