microbit-dal: ManagedString heap error

Some higher level languages initialise Strings and Images used RefCounted types. In certain scenarios, they could be initialised with NULL, there was no error checking for this case, and users observed error code 030 (a heap error). This was traced back to some error checking in RefCounted.cpp, where the reference is tested. In these initialisers the RefCounted type was NULL.

Added some additional error checking in ManagedString and ManagedImage.

Closes #283.
This commit is contained in:
James Devine 2017-04-22 23:57:36 +01:00
parent 74fa06c8d0
commit 58f8f0f22e
2 changed files with 12 additions and 0 deletions

View file

@ -91,6 +91,12 @@ void ManagedString::initString(const char *str)
*/
ManagedString::ManagedString(StringData *p)
{
if(p == NULL)
{
initEmpty();
return;
}
ptr = p;
ptr->incr();
}

View file

@ -207,6 +207,12 @@ MicroBitImage::MicroBitImage(const char *s)
*/
MicroBitImage::MicroBitImage(ImageData *p)
{
if(p == NULL)
{
init_empty();
return;
}
ptr = p;
ptr->incr();
}