github-vet / github-vet/rangeloop-pointer-findings
HWSkynet/yui-on-discord: main.go; 37 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [HWSkynet/yui-on-discord](https://www.github.com/HWSkynet/yui-on-discord) at [main.go](https://github.com/HWSkynet/yui-on-discord/blob/a0706d03d1c116c48abcbd34940d0ae576be8a37/main.go#L120-L156)
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 v used in defer or goroutine at line 125
[Click here to see the code in its original context.](https://github.com/HWSkynet/yui-on-discord/blob/a0706d03d1c116c48abcbd34940d0ae576be8a37/main.go#L120-L156)
Click here to show the 37 line(s) of Go which triggered the analyzer.
```go
for _, v := range m.Attachments {
if v.Width > 0 {
fmt.Printf("图片尺寸:%dx%d\n", v.Width, v.Height)
fmt.Println(v)
go func() {
res, err := http.Get(v.URL)
if err != nil {
panic(err)
}
f, err := os.Create(v.Filename)
if err != nil {
panic(err)
}
io.Copy(f, res.Body)
f.Close()
res.Body.Close()
img, err := imgio.Open(v.Filename)
if err != nil {
panic(err)
}
k := 300 / math.Max(float64(img.Bounds().Max.X), float64(img.Bounds().Max.Y))
w, h := int(math.Ceil(k*float64(img.Bounds().Max.X))), int(math.Ceil(k*float64(img.Bounds().Max.Y)))
result := effect.Median(transform.Resize(transform.Resize(img, w/8, h/8, transform.NearestNeighbor), w, h, transform.NearestNeighbor), 2)
if err := imgio.Save("output.jpg", result, imgio.JPEGEncoder(15)); err != nil {
panic(err)
}
os.Remove(v.Filename)
file, _ := os.OpenFile("output.jpg", os.O_RDONLY, 0)
dcuser, _ := s.User(m.Author.ID)
s.ChannelFileSend(talking_channel, "女装.jpg", file)
s.ChannelMessageSend(talking_channel, dcuser.Mention()+"在女装频道发布了图片,缩略图打码如上")
}()
}
}
```
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: a0706d03d1c116c48abcbd34940d0ae576be8a37
Contributor guide
No contributing guide indexed for this repository
Research direction
Read main.go lines 120-156 in the linked commit, focusing on the goroutine inside the range loop and how it uses v. Compare the analyzer warning with Go's range-variable behavior, then leave the reaction that best classifies whether this is a bug, mitigated, or desirable behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100