Repository navigation
Fix a panic on a field write through a slice element - #42
Merged
Merged
Conversation
The nonmutating analyzer stopped the whole run with exit status 2 on a
field write whose container was not an identifier. `containerStorageVisible`
accepted only an identifier and panicked on every other expression, and
`visibleMutationOrigin` called it for the container of each selector
write. These shapes crashed:
//constable:nonmutating
func F(s []E) { s[0].N = 1 } // *ast.IndexExpr
//constable:nonmutating
func G(p *E) { (*p).N = 1 } // *ast.StarExpr
//constable:nonmutating
func H(ss [][]E) { ss[0][0].N = 1 } // nested *ast.IndexExpr
A selector's container lives in caller-visible memory exactly when the
container expression does, so `exprRefersToCallerVisibleMemory` subsumes
`containerStorageVisible` for an identifier and answers for the other
shapes without a panic. Delete the narrower function and call the general
one at both sites.
`rootOrigin` finds the parameter or receiver that starts a chain, so a
write below an index or a dereference reports the identifier that the
caller passed. The same change removes two silent misses that the old
container check produced: `o.inner.data[0] = 0` on a value receiver now
reports, and so does `(*p).inner.data[0] = 0` on a pointer parameter.
Add regression cases for the three crashing shapes and for the value
receiver chain, which passed silently before. Keep `o.inner = Inner{}` as
a control: a field write on the receiver copy must stay unreported.
Change-Id: Iade884a097fb704a54fc026e0c9d245f54989fdc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.