A new check for -> on ManagedTypes.

This commit is contained in:
Jonathan Protzenko 2015-11-04 15:43:36 -08:00
parent 74542e66eb
commit b421ba5b69
2 changed files with 6 additions and 1 deletions

View file

@ -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

View file

@ -103,6 +103,8 @@ public:
* x->m(); // resolves to T::m
*/
T* operator->() {
if (object == NULL)
panic(MICROBIT_NULL_DEREFERENCE);
return object;
}