github-vet / github-vet/rangeloop-pointer-findings
waiyee/atmGOv2: main.go; 45 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [waiyee/atmGOv2](https://www.github.com/waiyee/atmGOv2) at [main.go](https://github.com/waiyee/atmGOv2/blob/b7081c81eab9fd6eac7e5484deef3aecf9cc54d1/main.go#L204-L248)
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 234
[Click here to see the code in its original context.](https://github.com/waiyee/atmGOv2/blob/b7081c81eab9fd6eac7e5484deef3aecf9cc54d1/main.go#L204-L248)
Click here to show the 45 line(s) of Go which triggered the analyzer.
```go
for _,v := range orders {
var ticker bittrex.Ticker
var err2 error
ticker, err2 = bAPI.GetTicker(v.Exchange)
for err != nil {
session := mydb.Session.Clone()
defer session.Close()
e := session.DB("v4").C("ErrorLog").With(session)
e.Insert(&db.ErrorLog{Description: "Get Ticker SetupOpeningOrder API - "+v.Exchange, Error: err2.Error(), Time: time.Now()})
ticker, err2 = bAPI.GetTicker(v.Exchange)
}
if v.OrderType == "LIMIT_BUY" {
MarketOrder[v.Exchange].Lock.Lock()
MarketOrder[v.Exchange].BuyAskPrice = ticker.Ask
MarketOrder[v.Exchange].BuyBidPrice = ticker.Bid
MarketOrder[v.Exchange].BuyOrderUUID = v.OrderUuid
MarketOrder[v.Exchange].BuyOpening = true
MarketOrder[v.Exchange].Lock.Unlock()
}else{
MarketOrder[v.Exchange].Lock.Lock()
MarketOrder[v.Exchange].SellAskPrice = ticker.Ask
MarketOrder[v.Exchange].SellBidPrice = ticker.Bid
MarketOrder[v.Exchange].SellOrderUUID = v.OrderUuid
MarketOrder[v.Exchange].SellOpening = true
MarketOrder[v.Exchange].Lock.Unlock()
}
askPrice := ticker.Ask - satoshi
go func() {
for range time.NewTicker(time.Millisecond * 150).C {
if MarketOrder[v.Exchange].BuyOpening && MarketOrder[v.Exchange].BuyOrderUUID != "" && MarketOrder[v.Exchange].CheckingBuy == "" {
MarketOrder[v.Exchange].CheckingBuy = MarketOrder[v.Exchange].BuyOrderUUID
go BuyMarket(v.Exchange, v.Price , askPrice)
}
if MarketOrder[v.Exchange].SellOpening && MarketOrder[v.Exchange].SellOrderUUID != "" && MarketOrder[v.Exchange].CheckingSell == ""{
MarketOrder[v.Exchange].CheckingSell = MarketOrder[v.Exchange].SellOrderUUID
go SellMarket(v.Exchange, v.Price )
}
if !(MarketOrder[v.Exchange].SellOpening && MarketOrder[v.Exchange].SellOrderUUID != "" ) && MarketOrder[v.Exchange].CheckingBuy == "" && !(MarketOrder[v.Exchange].BuyOpening && MarketOrder[v.Exchange].BuyOrderUUID != "") && MarketOrder[v.Exchange].CheckingSell == "" {
break
}
}
}()
}
```
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: b7081c81eab9fd6eac7e5484deef3aecf9cc54d1
Contributor guide
No contributing guide indexed for this repository
Research direction
Read main.go lines 204-248 at commit b7081c81eab9fd6eac7e5484deef3aecf9cc54d1, focusing on the range loop, defer, and goroutine that use v. Check whether the analyzer's range-loop capture warning represents a real bug in this context. Done means leaving the appropriate Bug, Mitigated, or Desirable Behavior reaction on the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100