append
possibly assigns to a wrong variable CRT-D000161 if len(lines) > h.maxSize {
62 lines = lines[len(lines)-h.maxSize:]
63 }
64 h.lines = append(lines, "")65 return ioutil.WriteFile(h.path, []byte(strings.Join(h.lines, "\n")), 0600)
66}
67
57 return nil
58 }
59
60 lines := append(h.lines[:len(h.lines)-1], line)61 if len(lines) > h.maxSize {
62 lines = lines[len(lines)-h.maxSize:]
63 }
The builtin function append
returns the updated slice after the append operation.
This resulting slice is usually assigned back to the same variable that contained
the original slice to which new values were appended.
x = []int{1, 3, 5}
append(x, 7) // returns the value []int{1, 3, 5, 7}. This is usually assigned back to x
x := []int{}
y := []int{}
x = append(y, 1) // possibly wrong
x = []int{1, 3, 5}
x = append(x, 7)
x := []int{}
y := []int{}
y = append(y, 1) // append 1 to y