Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miss makezero in slice init #2545

Closed
alingse opened this issue May 27, 2024 · 2 comments
Closed

miss makezero in slice init #2545

alingse opened this issue May 27, 2024 · 2 comments
Assignees

Comments

@alingse
Copy link

alingse commented May 27, 2024

Describe the bug

I was running github actions to run linter makezero for top github golang repos.

see issues alingse/go-linter-runner#1

and the github actions output https://github.com/alingse/go-linter-runner/actions/runs/9242995169/job/25426544240

====================================================================================================
append to slice `us` with non-zero initialized length at https://github.com/getgauge/gauge/blob/master/cmd/list.go#L131:[9](https://github.com/alingse/go-linter-runner/actions/runs/9242995169/job/25426544240#step:4:10)
====================================================================================================
func uniqueNonEmptyElementsOf(input []string) []string {
	unique := make(map[string]bool, len(input))
	us := make([]string, len(unique))
	for _, elem := range input {
		if len(elem) != 0 && !unique[elem] {
			us = append(us, elem)
			unique[elem] = true
		}
	}

	return us
}

the us is neither empty and neither unique

us := make([]string, len(unique)) should be us := make([]string, 0, len(unique))

To Reproduce
Steps (or project) to reproduce the behavior:

  1. Initialise a gauge project
  2. Run the gauge command
  3. See error
$ gauge init java # or js, python etc
$ gauge run specs

Logs

Paste any log or error messages here

Expected behavior
A clear and concise description of what you expect to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Versions:

gauge -v
  • OS [e.g. MacOS 10.15.6 (19G2021) please be specific ]
  • Runner info (Please specify the correct version of Java/Node/Python/Dotnet/Ruby)
  • IDE info (If using VS Code or Intellij IDEA)

Additional context
Add any other context about the problem here.

@chadlwilson
Copy link
Contributor

len(unique) is always 0 since this is a map allocated (not a slice), so this seems a false positive. Confusing code though.

@chadlwilson chadlwilson self-assigned this May 27, 2024
@alingse
Copy link
Author

alingse commented May 27, 2024

Yes you are right. LoL, this case is correct in a magic way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants