adding default values for beyond the array.length access
This commit is contained in:
		@@ -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) 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user