10 examples of 'index out of range' in Go

Every line of 'index out of range' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
189func isInBounds(data []byte, i int) bool {
190 return i >= 0 && i < len(data)
191}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

161func (heap *Heap) withinRange(index int) bool {
162 return index >= 0 && index < heap.list.Size()
163}
98func checkIndex(min, max, i int) error {
99 if i < min {
100 return NewErrBadIndex("%v, min=%v", i, min)
101 }
102 if i > max { // allow max
103 return NewErrBadIndex("%v, max=%v", i, max)
104 }
105 return nil
106}
293func (sc *SliceColumn) inBounds(i int) error {
294 if i >= 0 && i < sc.Len() {
295 return nil
296 }
297
298 return fmt.Errorf("index %d out of bounds [0:%d]", i, sc.Len())
299}
253func (Bool) IndexSet(index, value Object) error {
254 return ErrNotIndexAssignable
255}
269func (matrix *DenseFloat64Matrix) IntAt(i, j int) int {
270 return int(matrix.values[matrix.index(i, j)])
271}
77func (pstruct *Struct) SetIndex(index, value interface{}) int {
78 sindex := int(index.(int64))
79 if sindex < 0 || sindex >= len(pstruct.Values) {
80 return core.ErrIndexOut
81 }
82 pstruct.Values[sindex] = value
83 return 0
84}
88func (i *Int) InRange(lowerLimit int, upperLimit int) structure.Int {
89 if i.value != nil {
90 if *i.value < lowerLimit || *i.value > upperLimit {
91 i.base.ReportError(ErrorValueNotInRange(*i.value, lowerLimit, upperLimit))
92 }
93 }
94 return i
95}
213func (me *Int3x3) AccessIndex(i, j int) interface{} {
214 if j >= 0 {
215 i = index2D(i, j, len(me))
216 }
217 return &me[i]
218}
157func (s *Base) InRange(index int) bool {
158 return index >= 0 && index < s.Len()
159}

Related snippets