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

vexor/vx-binutils: cloud-files/action_put.go; 45 LoC

Open
#12,459 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 [vexor/vx-binutils](https://www.github.com/vexor/vx-binutils) at [cloud-files/action_put.go](https://github.com/vexor/vx-binutils/blob/b501ac77a33ef5b4e1a1051ef2eceb82e2cb2641/cloud-files/action_put.go#L114-L158)

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 c used in defer or goroutine at line 142

[Click here to see the code in its original context.](https://github.com/vexor/vx-binutils/blob/b501ac77a33ef5b4e1a1051ef2eceb82e2cb2641/cloud-files/action_put.go#L114-L158)

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

```go
for _, c := range put.containers {
objectNames, err := c.ListObjects()
if err != nil {
LogError("[%s:%s] List objects errors: %s", c.Region, c.Name, err.Error())
os.Exit(1)
}

toDestroy := []string{}
for _, o := range objectNames {
name := o

if prefix != "" {
if len(o) < len(prefix) {
name = ""
} else {
name = o[len(prefix):len(o)]
}
}

if put.dir.Md5[name] == "" {
toDestroy = append(toDestroy, o)
}
}

if len(toDestroy) > 0 {
LogNl()
go func(){
for _, o := range toDestroy {
in <- ActionPutDelReq{ c: c, o: o }
}
}()

total := len(toDestroy)

for err := range out {
LogFatal(err)
total--

LogInfoR("[%s:%s] delete %d of %d", c.Region, c.Name, len(toDestroy) - total, len(toDestroy))
if total == 0 {
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: b501ac77a33ef5b4e1a1051ef2eceb82e2cb2641

Contributor guide

No contributing guide indexed for this repository

Research direction

Read cloud-files/action_put.go lines 114-158 at commit b501ac77a33ef5b4e1a1051ef2eceb82e2cb2641, focusing on the goroutine and its use of the range variable c. Compare the reported analyzer warning with the surrounding deletion flow, then leave the requested reaction classifying it as Bug, Mitigated, or Desirable Behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.