Skip to content

Generated code triggers gosec G601 "Implicit memory aliasing in for loop." #75

@myshkin5

Description

@myshkin5

Code is iterating, grabbing the wanted value, then breaking:

	for n, res := range r.Moq.ResultsByParams_XXX {
		if res.AnyParams == r.AnyParams {
			results = &res
			break
		}
		if res.AnyCount > anyCount {
			insertAt = n
		}
	}

Could use the index to avoid the linter issue:

	for n, res := range r.Moq.ResultsByParams_XXX {
		if res.AnyParams == r.AnyParams {
			results = &r.Moq.ResultsByParams_XXX[n]
			break
		}
		if res.AnyCount > anyCount {
			insertAt = n
		}
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions