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

modify-by-receiver: PoC of what is not detected yet #1180

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions testdata/modifies_value_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,48 @@ func (this data) assignmentOperators() {
this.num >>= 1 // MATCH /suspicious assignment to a by-value method receiver/
this.num <<= 1 // MATCH /suspicious assignment to a by-value method receiver/
}

type rfoo struct {
CntP *int
Cnt int
rbar
*rquz
RBar rbar
PRBar *rbar
}

type rbar struct {
BCntP *int
BCnt int
}

type rquz struct {
QCnt int
}

func (foo rfoo) increment() {
// these are detected
foo.Cnt++ // MATCH /suspicious assignment to a by-value method receiver/
foo.BCnt++ // MATCH /suspicious assignment to a by-value method receiver/

// this one is only a another notation for foo.BCnt++
foo.rbar.BCnt++ // MATCH /this one should be detected, no?/
// this on
foo.RBar.BCnt++ // MATCH /this one should be detected, no?/

// here, we are updating the pointer of a non-pointer receiver
// right now it's not reported, shouldn't it ?
*foo.CntP++ // MATCH /what do we want for this one?/

// here rquz is a pointer struct, it should not be detected, right ?
foo.QCnt++ // MATCH /we shouldn't report this one, right?/

// same here, it should be detected, no ?
*foo.rbar.BCntP++ // MATCH /what do we want for this one?/
*foo.BCntP++ // MATCH /what do we want for this one?/

// these rely on pointers, they should not be detected, right?
*foo.RBar.BCntP++ // MATCH /what do we want for this one?/
*foo.PRBar.BCntP++ // MATCH /what do we want for this one?/
foo.PRBar.BCnt++ // MATCH /what do we want for this one?/
}
Loading