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

Vet source code using NilAway #73

Merged
merged 1 commit into from
Dec 6, 2023
Merged

Vet source code using NilAway #73

merged 1 commit into from
Dec 6, 2023

Conversation

ericcornelissen
Copy link
Owner

@ericcornelissen ericcornelissen commented Nov 25, 2023

Relates to #48, #52, #55

Summary

Add NilAway as a new vet check in order to detect and address potential runtime errors due to nil values. It found 4 problems as of fa28274, which have all been addressed.

One of the findings was a false positive for which an alternative implementation was feasible (and favorable in terms of memory usage). While the overall assessment as of this Pull Request is that the false positives are tolerable, having false positives is not ideal for a tool that is continuously run. If it turns out to be a problem the continuous usage of NilAway will be reconsidered.

@ericcornelissen ericcornelissen added dependencies Changes to the project's dependencies refactor Changes existing code without changing functionality labels Dec 5, 2023
Add NilAway (<https://github.com/uber-go/nilaway>) as a new vet check in
order to detect and address potential runtime errors due to nil values.

All 4 violations it detected have been addressed. In `analyze.go` this
simply constitutes checking that received pointers aren't nil. In
`main.go` this constites, first, explicitly relying on the `ok` check of
a map lookup when trying to use said key (instead of implicitly relying
on the control flow being such that said key is injected if it isn't
there already), and second, rewriting to avoid using `strings.Split` and
instead using index lookup - in this case the finding by NilAway was a
false positive (`nil` can never be returned by `strings.Split`, even if
the internal function used may return `nil` in some cases) but rewriting
reduces memory usage.

The modifications are partially tested, covering only `analyze.go`
because `main.go` isn't covered by unit tests.

Signed-off-by: Eric Cornelissen <ericornelissen@gmail.com>
@ericcornelissen ericcornelissen marked this pull request as ready for review December 5, 2023 22:10
@ericcornelissen ericcornelissen merged commit 3c008e6 into main Dec 6, 2023
11 checks passed
@ericcornelissen ericcornelissen deleted the nilaway branch December 6, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Changes to the project's dependencies refactor Changes existing code without changing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant