github-vet / github-vet/rangeloop-pointer-findings

iamdaiyuan/dudu: tool/url/de_urlmain.go; 93 LoC

Open
#10,994 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [iamdaiyuan/dudu](https://www.github.com/iamdaiyuan/dudu) at [tool/url/de_urlmain.go](https://github.com/iamdaiyuan/dudu/blob/612e835eb8a9919f069f69615721e153a8c26197/tool/url/de_urlmain.go#L52-L144)

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 index used in defer or goroutine at line 54

[Click here to see the code in its original context.](https://github.com/iamdaiyuan/dudu/blob/612e835eb8a9919f069f69615721e153a8c26197/tool/url/de_urlmain.go#L52-L144)

Click here to show the 93 line(s) of Go which triggered the analyzer.

```go
for index, v := range process {
go func(v []string) {
ip := "*" + util.IS(index)
ipbegintimes := ""
if proxy {
ip = core.GetIP()

// before use, send to hash pool
ipbegintimes = util.GetSecord2DateTimes(util.GetSecordTimes())
core.RedisClient.Hset(core.MyConfig.Proxyhashpool, ip, ipbegintimes)
}
for _, file := range v {

tempbytecont, _ := util.ReadfromFile(file)
tempurls := strings.Split(string(tempbytecont), "\n")
//core.LocalLogger.Debugf("%#v",tempurls)
for _, url := range tempurls {
tempurl := strings.Split(url, ",")
num := tempurl[0]
a := dir + "/" + num + ".html"
b := dir + "/" + num + ".md"
c := dir + "/" + num + ".mdxx"
fileok := util.FileExist(a)
filemdok := util.FileExist(b)
filemdokxx := util.FileExist(c)
reallyurl := tempurl[1]
if strings.Contains(reallyurl, "books") {
fmt.Printf("%s,%s是书籍,重复!!\n", num, reallyurl)
continue
}
if filemdokxx {
fmt.Printf("%s,%s没有下级\n", num, reallyurl)
continue
}
if filemdok && fileok {
fmt.Printf("%s,%s已经抓过和处理过\n", num, reallyurl)
continue
}
urlcont := []byte("")
var e error = nil
if fileok {
fmt.Printf("%s,%s已经抓过\n", num, reallyurl)
urlcont, e = util.ReadfromFile(a)
if e != nil {
fmt.Printf("%s,%s打开失败:%s\n", num, reallyurl, e.Error())
}
} else {
for {
urlcont, e = core.Download(ip, reallyurl)
util.Sleep(wait)
if e != nil {
fmt.Printf("%s,%s抓取失败:%s\n", num, reallyurl, e.Error())
continue
}
spider, ok := core.Spiders.Get(ip)
if robot(urlcont) {
fmt.Printf("%s,%s抓取机器人!!!\n", num, reallyurl)
if ok {
spider.Errortimes = spider.Errortimes + 1
}
} else {
break
}
// if proxy ip err more than config, change ip
if proxy && ok && spider.Errortimes > core.MyConfig.Proxymaxtrytimes {
// die sent
ipendtimes := util.GetSecord2DateTimes(util.GetSecordTimes())
insidetemp := ipbegintimes + "|" + ipendtimes + "|" + util.IS(spider.Fetchtimes-spider.Errortimes) + "|" + util.IS(spider.Errortimes)
core.RedisClient.Hset(core.MyConfig.Proxyhashpool, ip, insidetemp)
// you know it
core.Spiders.Delete(ip)
// get new proxy again
ip = core.GetIP()
ipbegintimes = util.GetSecord2DateTimes(util.GetSecordTimes())
core.RedisClient.Hset(core.MyConfig.Proxyhashpool, ip, ipbegintimes)
}
}
util.SaveToFile(a, urlcont)
}
if filemdok == false {
md := parseurl(num, urlcont, level+2)
if len(md) == 0 {
util.SaveToFile(c, []byte(""))
} else {
util.SaveToFile(b, []byte(strings.Join(md, "\n")))
}
}
}

}
urlchan <- "done"
}(v)
}

```

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: 612e835eb8a9919f069f69615721e153a8c26197

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.