From 98ffcc1fd1bdd80f8229d9d2a759f63939914ce9 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Sun, 25 Oct 2015 12:59:45 -0700 Subject: [PATCH] Add status panic codes for ref-count errors --- inc/ErrorNo.h | 8 +++++++- source/RefCounted.cpp | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/inc/ErrorNo.h b/inc/ErrorNo.h index 84a37d6..19c6e62 100644 --- a/inc/ErrorNo.h +++ b/inc/ErrorNo.h @@ -22,6 +22,12 @@ enum Error{ MICROBIT_OOM = 20, // Corruption detected in the micro:bit heap space - MICROBIT_HEAP_ERROR = 30 + MICROBIT_HEAP_ERROR = 30, + + // refcounter on an object is invalid (memory corruption) + MICROBIT_REF_COUNT_CORRUPTION = 31, + + // refcounter was incremented/decremented after it already reached zero + MICROBIT_USE_AFTER_FREE = 32, }; #endif diff --git a/source/RefCounted.cpp b/source/RefCounted.cpp index b8d646e..4ed60c1 100644 --- a/source/RefCounted.cpp +++ b/source/RefCounted.cpp @@ -16,10 +16,10 @@ static inline bool isReadOnlyInline(RefCounted *t) // Do some sanity checking while we're here if (refCount == 1) - uBit.panic(30); // object should have been deleted + uBit.panic(MICROBIT_USE_AFTER_FREE); // object should have been deleted if ((refCount & 1) == 0) - uBit.panic(31); // refCount doesn't look right + uBit.panic(MICROBIT_REF_COUNT_CORRUPTION); // refCount doesn't look right // Not read only return false;