Skip to content

append-to-sized-slice

Default severity: warning

make([]T, n) with a compile-time positive n creates n existing zero values. If the intent is to append up to n values, use make([]T, 0, n) so the result does not begin with zeros. Runtime lengths are left alone when the analyzer cannot prove that they are positive.

values := make([]int, count)
values = append(values, next)
values := make([]int, 0, count)
values = append(values, next)