github-vet / github-vet/rangeloop-pointer-findings
mapleFU/QQGroupBot: qqbot/service/query/SauceNao.go; 109 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [mapleFU/QQGroupBot](https://www.github.com/mapleFU/QQGroupBot) at [qqbot/service/query/SauceNao.go](https://github.com/mapleFU/QQGroupBot/blob/79f6ad11f51a8a4a8042241bc1e2b9b15815a192/qqbot/service/query/SauceNao.go#L46-L154)
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 seg used in defer or goroutine at line 49
[Click here to see the code in its original context.](https://github.com/mapleFU/QQGroupBot/blob/79f6ad11f51a8a4a8042241bc1e2b9b15815a192/qqbot/service/query/SauceNao.go#L46-L154)
Click here to show the 109 line(s) of Go which triggered the analyzer.
```go
for _, seg := range data.Message {
if seg.Type == "image" {
go func() {
imageLink, ok := image.GetImage(&seg)
img := imgbase64.FromRemote(imageLink)
//fmt.Println(img)
if !ok {
return
}
//resp, err := http.Get(imageLink)
//
//
//fmt.Println("Debug: 走到这了3")
//if err != nil {
// fmt.Println("http error")
// fmt.Println(err.Error())
// return
//}
//defer resp.Body.Close()
//bytesData, err := ioutil.ReadAll(resp.Body)
//fmt.Println("Debug: 走到这了2")
//if err != nil {
// fmt.Println("read file error")
// fmt.Println(err.Error())
// return
//}
//fmt.Println("Debug: 走到这了1")
//ext := filepath.Ext(seg.Data.File)[1:]
//
//mimeData := fmt.Sprintf("data:image/%s;base64,%s", ext, base64.StdEncoding.EncodeToString(bytesData))
//
bytesData, err := json.Marshal(map[string]string{
"image": img,
})
////b64_out, err := os.Create("/home/user/log/base64.log")
////outData := bufio.NewReader(b64_out)
////w := bytes.NewReader(bytesData)
////defer b64_out.Close()
////io.Copy(b64_out, w)
//
//fmt.Println("Debug: 走到这了0")
//if err != nil {
// fmt.Println(err.Error())
// return
//}
//
//fmt.Println("Debug: 走到这了-1")
respSearch, err := http.Post("https://trace.moe/api/search", "application/json", bytes.NewBuffer(bytesData))
if err != nil {
fmt.Println("http POST 请求异常")
fmt.Println(err.Error())
return
}
if respSearch.StatusCode != http.StatusOK {
fmt.Println(fmt.Sprintf("http resp code %d", respSearch.StatusCode))
return
}
defer respSearch.Body.Close()
strData, err := ioutil.ReadAll(respSearch.Body)
if err != nil {
fmt.Println(err.Error())
return
}
//fmt.Println(string(strData))
var target search.SearchResult
err = json.NewDecoder(bytes.NewBuffer(strData)).Decode(&target)
if err != nil {
fmt.Println("search.SearchResult 解码异常")
fmt.Println(err.Error())
}
//if err = json.NewDecoder(respSearch.Body).Decode(&target); err != nil {
// fmt.Println("search.SearchResult 解码异常")
// // DEBUG
// out, err := os.Open("/home/user/log/http-response.log")
// w, err := ioutil.ReadAll(respSearch.Body)
// if err != nil {
// // panic?
// fmt.Println(err.Error())
//
// fmt.Println(string(w))
// }
// fmt.Println(string(w))
// defer out.Close()
// io.Copy(out, respSearch.Body)
// //fmt.Println(err.Error())
// return
//}
//jsonData, err := json.Marshal(target)
//if err != nil {
// fmt.Println("search.SearchResult 解码异常")
// fmt.Println(err.Error())
// return
//}
Resp := group.StringRespMessage{
Message: target.String(),
GroupID: "",
AutoEscape: true,
}
fmt.Println("Ready to send")
*snq.OutChan <- Resp
fmt.Println("Send done")
}()
}
}
```
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: 79f6ad11f51a8a4a8042241bc1e2b9b15815a192
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.