suspicious assignment to a by-value method receiver #7966

Closed
opened 2025-11-02 07:42:59 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @chavacava on GitHub (Oct 12, 2021).

7bcbdd0707/modules/graceful/server.go (L266-L278)

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)

Originally created by @chavacava on GitHub (Oct 12, 2021). https://github.com/go-gitea/gitea/blob/7bcbdd07072d375eb9f24a64a047879ae2aa7aed/modules/graceful/server.go#L266-L278 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](https://github.com/mgechev/revive))
Author
Owner

@zeripath commented on GitHub (Oct 12, 2021):

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 commented on GitHub (Oct 12, 2021): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#7966