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

suspicious assignment to a by-value method receiver #17294

Closed
chavacava opened this issue Oct 12, 2021 · 1 comment · Fixed by #17295
Closed

suspicious assignment to a by-value method receiver #17294

chavacava opened this issue Oct 12, 2021 · 1 comment · Fixed by #17295

Comments

@chavacava
Copy link
Contributor

chavacava commented Oct 12, 2021

func (w wrappedConn) Write(p []byte) (n int, err error) {
if w.perWriteTimeout > 0 {
minTimeout := time.Duration(len(p)/1024) * w.perWritePerKbTimeout
minDeadline := time.Now().Add(minTimeout).Add(w.perWriteTimeout)
w.deadline = w.deadline.Add(minTimeout)
if minDeadline.After(w.deadline) {
w.deadline = minDeadline
}
_ = w.Conn.SetWriteDeadline(w.deadline)
}
return w.Conn.Write(p)
}

The assignments to w.deadline (lines 271 and 273) have no effect outside the scope of the method ( e.g. https://play.golang.org/p/eM0ehqmH7Yj)

(Found by revive)

@zeripath
Copy link
Contributor

Thanks, but it would have been easier to understand if you'd just said we should be using pointer methods rather than non-pointer methods.

The reason why the bug was added was because the Close() method below didn't need to be a pointer method as initially everything in the wrappedConn struct was a pointer. Thus when I added the Write method this was missed.

zeripath added a commit to zeripath/gitea that referenced this issue Oct 12, 2021
Fix go-gitea#17294

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Oct 12, 2021
Fix #17294

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this issue Oct 12, 2021
Backport go-gitea#17295

Fix go-gitea#17294

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit that referenced this issue Oct 12, 2021
Backport #17295

Fix #17294

Signed-off-by: Andrew Thornton <art27@cantab.net>
Chianina pushed a commit to Chianina/gitea that referenced this issue Oct 15, 2021
Fix go-gitea#17294

Signed-off-by: Andrew Thornton <art27@cantab.net>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants