Skip to content

False positive: slice does not have non-zero initial length (makezero) incorrectly reported when slice length is explicitly set. #22

@Shubham-iron

Description

@Shubham-iron

The linter reports the warning:

slice 'result' does not have non-zero initial length (makezero)

even when the slice is explicitly created with a non-zero length.

func initUserScores(users []string, defaultScore int) map[string][]int {
	result := make(map[string][]int, len(users))
	template := []int{defaultScore, defaultScore}

	for _, u := range users {
		// Pre-allocate exact slice length
		result[u] = make([]int, len(template))
		copy(result[u], template)
	}

	return result
}

Can we handle these type of cases where function like copy are immediately next to declaration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions