github-vet / github-vet/rangeloop-pointer-findings
inancgumus/learngo: advfuncs/08-png-detector/main.go; 31 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [inancgumus/learngo](https://www.github.com/inancgumus/learngo) at [advfuncs/08-png-detector/main.go](https://github.com/inancgumus/learngo/blob/c9e9dd46a6278e83a796c2566ffaec34461594cf/advfuncs/08-png-detector/main.go#L115-L145)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable filename used in defer or goroutine at line 124
[Click here to see the code in its original context.](https://github.com/inancgumus/learngo/blob/c9e9dd46a6278e83a796c2566ffaec34461594cf/advfuncs/08-png-detector/main.go#L115-L145)
Click here to show the 31 line(s) of Go which triggered the analyzer.
```go
for _, filename := range filenames {
fmt.Printf("processing: %s\n", filename)
file, err := os.Open(filename)
if err != nil {
continue
}
defer func() {
fmt.Printf("closes : %s\n", filename)
file.Close()
}()
fi, err := file.Stat()
if err != nil {
continue
}
if fi.Size() <= int64(len(pngHeader)) {
continue
}
_, err = io.ReadFull(file, buf)
if err != nil {
continue
}
if bytes.Equal([]byte(pngHeader), buf) {
pngs = append(pngs, filename)
}
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: c9e9dd46a6278e83a796c2566ffaec34461594cf
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading advfuncs/08-png-detector/main.go at lines 115-145, focusing on the deferred function inside the filename loop and the analyzer report at line 124. Determine whether the finding is a Bug, Mitigated, or Desirable Behavior, then leave the corresponding reaction on the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100