adding default values for beyond the array.length access

This commit is contained in:
Brahma Giri Abhijith Chatra 2017-01-08 19:08:09 -08:00
parent 91321dab83
commit c938618d29

View File

@ -152,7 +152,6 @@ namespace pxt {
{
return data[i];
}
error(ERR_OUT_OF_BOUNDS);
return Segment::DefaultValue;
}
@ -275,7 +274,6 @@ namespace pxt {
--length;
return value;
}
error(ERR_OUT_OF_BOUNDS);
return Segment::DefaultValue;
}
@ -304,7 +302,6 @@ namespace pxt {
#endif
return ret;
}
error(ERR_OUT_OF_BOUNDS);
return Segment::DefaultValue;
}
@ -387,29 +384,16 @@ namespace pxt {
uint32_t RefCollection::getAt(int i)
{
if (head.isValidIndex(i))
uint32_t tmp = head.get(i);
if (isRef())
{
uint32_t tmp = head.get(i);
if (isRef())
{
incr(tmp);
}
return tmp;
}
else
{
error(ERR_OUT_OF_BOUNDS);
return 0;
incr(tmp);
}
return tmp;
}
uint32_t RefCollection::removeAt(int i)
{
if (!head.isValidIndex((uint32_t)i))
{
error(ERR_OUT_OF_BOUNDS);
return 0;
}
if (isRef())
{
decr(head.get(i));
@ -419,18 +403,11 @@ namespace pxt {
void RefCollection::insertAt(int i, uint32_t value)
{
if (((uint32_t)i) < length())
head.insert(i, value);
if (isRef())
{
head.insert(i, value);
if (isRef())
{
incr(value);
}
}
else
{
error(ERR_OUT_OF_BOUNDS);
}
incr(value);
}
}
void RefCollection::setAt(int i, uint32_t value)