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]; return data[i];
} }
error(ERR_OUT_OF_BOUNDS);
return Segment::DefaultValue; return Segment::DefaultValue;
} }
@ -275,7 +274,6 @@ namespace pxt {
--length; --length;
return value; return value;
} }
error(ERR_OUT_OF_BOUNDS);
return Segment::DefaultValue; return Segment::DefaultValue;
} }
@ -304,7 +302,6 @@ namespace pxt {
#endif #endif
return ret; return ret;
} }
error(ERR_OUT_OF_BOUNDS);
return Segment::DefaultValue; return Segment::DefaultValue;
} }
@ -386,8 +383,6 @@ namespace pxt {
} }
uint32_t RefCollection::getAt(int i) uint32_t RefCollection::getAt(int i)
{
if (head.isValidIndex(i))
{ {
uint32_t tmp = head.get(i); uint32_t tmp = head.get(i);
if (isRef()) if (isRef())
@ -396,20 +391,9 @@ namespace pxt {
} }
return tmp; return tmp;
} }
else
{
error(ERR_OUT_OF_BOUNDS);
return 0;
}
}
uint32_t RefCollection::removeAt(int i) uint32_t RefCollection::removeAt(int i)
{ {
if (!head.isValidIndex((uint32_t)i))
{
error(ERR_OUT_OF_BOUNDS);
return 0;
}
if (isRef()) if (isRef())
{ {
decr(head.get(i)); decr(head.get(i));
@ -418,8 +402,6 @@ namespace pxt {
} }
void RefCollection::insertAt(int i, uint32_t value) void RefCollection::insertAt(int i, uint32_t value)
{
if (((uint32_t)i) < length())
{ {
head.insert(i, value); head.insert(i, value);
if (isRef()) if (isRef())
@ -427,11 +409,6 @@ namespace pxt {
incr(value); incr(value);
} }
} }
else
{
error(ERR_OUT_OF_BOUNDS);
}
}
void RefCollection::setAt(int i, uint32_t value) void RefCollection::setAt(int i, uint32_t value)
{ {