Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit d96ec0d

Browse files
authored
Merge pull request timakin#14 from ldez/fix/maxbytesreader
fix: call method nil.
2 parents 4a873e9 + 41875bb commit d96ec0d

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

passes/bodyclose/bodyclose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (r *runner) isCloseCall(ccall ssa.Instruction) bool {
227227
return true
228228
}
229229
case *ssa.Call:
230-
if ccall.Call.Method.Name() == r.closeMthd.Name() {
230+
if ccall.Call.Method != nil && ccall.Call.Method.Name() == r.closeMthd.Name() {
231231
return true
232232
}
233233
case *ssa.ChangeInterface:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package a
2+
3+
import (
4+
"io"
5+
"net/http"
6+
)
7+
8+
func issue4_1() {
9+
resp, _ := http.Get("https://example.com") // want "response body must be closed"
10+
11+
foo(resp.Body)
12+
}
13+
14+
func foo(r io.ReadCloser) {}
15+
16+
func issue4_2() {
17+
resp, _ := http.Get("https://example.com") // want "response body must be closed"
18+
19+
_ = http.MaxBytesReader(nil, resp.Body, 1024)
20+
}

0 commit comments

Comments
 (0)