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

JackyCZJ/Go-RemoteOVN: handler/ovn/lr.go; 42 LoC

Open
#11,572 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [JackyCZJ/Go-RemoteOVN](https://www.github.com/JackyCZJ/Go-RemoteOVN) at [handler/ovn/lr.go](https://github.com/JackyCZJ/Go-RemoteOVN/blob/90a7942300bcb7369a1be8b64780867089ccf212/handler/ovn/lr.go#L184-L225)

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 195

[Click here to see the code in its original context.](https://github.com/JackyCZJ/Go-RemoteOVN/blob/90a7942300bcb7369a1be8b64780867089ccf212/handler/ovn/lr.go#L184-L225)

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

```go
for _, v := range cmd {
wg := sync.WaitGroup{}
str, _ := jsoniter.Marshal(v)
err := jsoniter.Unmarshal(str, &LRP)
if err != nil {
log.Fatal("struct unmarshal error :%v", err)
}
wg.Add(3)
go func() {
defer wg.Done()
mapString := make(map[string]string)
for i, v := range v.ExternalID {
strKey := fmt.Sprintf("%v", i)
strValue := fmt.Sprintf("%v", v)
mapString[strKey] = strValue
}
LRP.ExternalID = mapString
}()
go func() {
defer wg.Done()
mapString := make(map[string]string)
for i, v := range v.IPv6RAConfigs {
strKey := fmt.Sprintf("%v", i)
strValue := fmt.Sprintf("%v", v)
mapString[strKey] = strValue
}
LRP.IPv6RAConfigs = mapString
}()
go func() {
defer wg.Done()
mapString := make(map[string]string)
for i, v := range v.Options {
strKey := fmt.Sprintf("%v", i)
strValue := fmt.Sprintf("%v", v)
mapString[strKey] = strValue
}
LRP.Options = mapString
}()
wg.Wait()

LRPs = append(LRPs, LRP)
}

```

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: 90a7942300bcb7369a1be8b64780867089ccf212

Contributor guide

No contributing guide indexed for this repository

Research direction

Open handler/ovn/lr.go at lines 184-225 in commit 90a7942300bcb7369a1be8b64780867089ccf212. Review the range loop and its three goroutines against the analyzer message about variable v, then determine whether the finding is a Bug, Mitigated, or Desirable Behavior. Leave the corresponding reaction on this 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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.