diff --git a/gnovm/pkg/gnolang/op_expressions.go b/gnovm/pkg/gnolang/op_expressions.go index b614e72e945..c0f6225740b 100644 --- a/gnovm/pkg/gnolang/op_expressions.go +++ b/gnovm/pkg/gnolang/op_expressions.go @@ -88,20 +88,20 @@ func (m *Machine) doOpSelector() { func (m *Machine) doOpSlice() { sx := m.PopExpr().(*SliceExpr) - var low, high, max int = -1, -1, -1 + var lowVal, highVal, maxVal int = -1, -1, -1 // max if sx.Max != nil { - max = m.PopValue().ConvertGetInt() + maxVal = m.PopValue().ConvertGetInt() } // high if sx.High != nil { - high = m.PopValue().ConvertGetInt() + highVal = m.PopValue().ConvertGetInt() } // low if sx.Low != nil { - low = m.PopValue().ConvertGetInt() + lowVal = m.PopValue().ConvertGetInt() } else { - low = 0 + lowVal = 0 } // slice base x xv := m.PopValue() @@ -114,14 +114,14 @@ func (m *Machine) doOpSlice() { } // fill default based on xv if sx.High == nil { - high = xv.GetLength() + highVal = xv.GetLength() } // all low:high:max cases - if max == -1 { - sv := xv.GetSlice(m.Alloc, low, high) + if maxVal == -1 { + sv := xv.GetSlice(m.Alloc, lowVal, highVal) m.PushValue(sv) } else { - sv := xv.GetSlice2(m.Alloc, low, high, max) + sv := xv.GetSlice2(m.Alloc, lowVal, highVal, maxVal) m.PushValue(sv) } } @@ -593,16 +593,16 @@ func (m *Machine) doOpSliceLit2() { // peek slice type. st := m.PeekValue(1).V.(TypeValue).Type // calculate maximum index. - max := 0 + maxVal := 0 for i := 0; i < el; i++ { itv := tvs[i*2+0] idx := itv.ConvertGetInt() - if idx > max { - max = idx + if idx > maxVal { + maxVal = idx } } // construct element buf slice. - es := make([]TypedValue, max+1) + es := make([]TypedValue, maxVal+1) for i := 0; i < el; i++ { itv := tvs[i*2+0] vtv := tvs[i*2+1] diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index e7a6274a780..4c2e2835f95 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -2248,41 +2248,41 @@ func (tv *TypedValue) GetSlice(alloc *Allocator, low, high int) TypedValue { } } -func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue { - if low < 0 { +func (tv *TypedValue) GetSlice2(alloc *Allocator, lowVal, highVal, maxVal int) TypedValue { + if lowVal < 0 { panic(fmt.Sprintf( "invalid slice index %d (index must be non-negative)", - low)) + lowVal)) } - if high < 0 { + if highVal < 0 { panic(fmt.Sprintf( "invalid slice index %d (index must be non-negative)", - high)) + highVal)) } - if max < 0 { + if maxVal < 0 { panic(fmt.Sprintf( "invalid slice index %d (index must be non-negative)", - max)) + maxVal)) } - if low > high { + if lowVal > highVal { panic(fmt.Sprintf( "invalid slice index %d > %d", - low, high)) + lowVal, highVal)) } - if high > max { + if highVal > maxVal { panic(fmt.Sprintf( "invalid slice index %d > %d", - high, max)) + highVal, maxVal)) } - if tv.GetCapacity() < high { + if tv.GetCapacity() < highVal { panic(fmt.Sprintf( "slice bounds out of range [%d:%d:%d] with capacity %d", - low, high, max, tv.GetCapacity())) + lowVal, highVal, maxVal, tv.GetCapacity())) } - if tv.GetCapacity() < max { + if tv.GetCapacity() < maxVal { panic(fmt.Sprintf( "slice bounds out of range [%d:%d:%d] with capacity %d", - low, high, max, tv.GetCapacity())) + lowVal, highVal, maxVal, tv.GetCapacity())) } switch bt := baseOf(tv.T).(type) { case *ArrayType: @@ -2294,15 +2294,15 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue return TypedValue{ T: st, V: alloc.NewSlice( - av, // base - low, // low - high-low, // length - max-low, // maxcap + av, // base + lowVal, // low + highVal-lowVal, // length + maxVal-lowVal, // maxcap ), } case *SliceType: if tv.V == nil { - if low != 0 || high != 0 || max != 0 { + if lowVal != 0 || highVal != 0 || maxVal != 0 { panic("nil slice index out of range") } return TypedValue{ @@ -2314,10 +2314,10 @@ func (tv *TypedValue) GetSlice2(alloc *Allocator, low, high, max int) TypedValue return TypedValue{ T: tv.T, V: alloc.NewSlice( - sv.Base, // base - sv.Offset+low, // offset - high-low, // length - max-low, // maxcap + sv.Base, // base + sv.Offset+lowVal, // offset + highVal-lowVal, // length + maxVal-lowVal, // maxcap ), } default: