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

range-val-address: fix false positive #554

Merged
merged 4 commits into from
Aug 26, 2021
Merged

range-val-address: fix false positive #554

merged 4 commits into from
Aug 26, 2021

Conversation

bernhardreisenberger
Copy link
Contributor

This PR fixes the false positive detected by archseer. i added a few more tests too.

Closes #553

@archseer
Copy link

Thanks for the quick fix! This looks good to me.

@chavacava
Copy link
Collaborator

Hi @bernhardreisenberger, thanks for the bug fix (and sorry for the late response)

Testing the fix against Kubernetes code base (kubernetes/vendor/...) raised a nil pointer dereference:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x6bbcd2]

goroutine 2022 [running]:
github.com/mgechev/revive/rule.rangeValAddress.Visit(0xc009fe3400, 0xc00a2ff1d0, 0x7d1f60, 0xc009fc5db0, 0x7ceec0, 0xc00b8fd510)
	/workspaces/revive/rule/range-val-address.go:56 +0x72

https://github.com/bernhardreisenberger/revive/blob/4f55759aa2d003b1efc1c58623ed2fd0f616bbb3/rule/range-val-address.go#L53-L56

	t := w.file.Pkg.TypeOf(value)

	ast.Walk(rangeBodyVisitor{
		valueIsStarExpr: strings.HasPrefix(t.String(), "*"),

It seems that t is nil in some cases thus t.String() fails. The origin of this problem might be that file.Pkg.TypeCheck() is returning an error but we do not check for it.

nit: the README.md need to be updated to indicate that the rule is typed

@bernhardreisenberger
Copy link
Contributor Author

Hi @chavacava

README.md is updated, and nil pointer dereference is fixed. should work fine now.

@chavacava chavacava merged commit 406b1ce into mgechev:master Aug 26, 2021
@chavacava
Copy link
Collaborator

Thanks @bernhardreisenberger!

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

Successfully merging this pull request may close these issues.

range-val-address false positive
3 participants