github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/staticcheck/testdata/src/_CheckSliceOutOfBounds.go.disabled (about)

     1  package pkg
     2  
     3  func fn1() {
     4  	var s []int
     5  	s[0] = 0 // MATCH /index out of bounds/
     6  }
     7  
     8  func fn2() {
     9  	s := make([]int, 2)
    10  	s[2] = 0 // MATCH /index out of bounds/
    11  }
    12  
    13  func fn3() {
    14  	var s []int
    15  	s[0] = 0 // MATCH /index out of bounds/
    16  
    17  	s = make([]int, 2)
    18  	s[2] = 0 // MATCH /index out of bounds/
    19  }
    20  
    21  func fn4() {
    22  	s := make([]int, 2)
    23  	s = append(s, 1)
    24  	s[0] = 0
    25  	s[1] = 0
    26  	s[2] = 0
    27  	s[3] = 0 // MATCH /index out of bounds/
    28  }
    29  
    30  func fn5(s []int) {
    31  	s[2] = 0
    32  }
    33  
    34  func fn6(s []int) {
    35  	s = s[:2]
    36  	s[2] = 0 // MATCH /index out of bounds/
    37  }
    38  
    39  func fn7() {
    40  	s := make([]int, 2)
    41  	fn(s[2]) // MATCH /index out of bounds/
    42  }
    43  
    44  func fn8() {
    45  	s := []int{}
    46  	s[0] = 1 // MATCH /index out of bounds/
    47  }
    48  
    49  func fn9() {
    50  	s := []int{}
    51  	ptr(&s)
    52  	s[0] = 1
    53  }
    54  
    55  func fn10() {
    56  	var x []byte
    57  	for _, y := range x {
    58  		println(y)
    59  	}
    60  }
    61  
    62  func fn(int) {
    63  	println() // make it unpure
    64  }
    65  func ptr(*[]int) {}