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; }