github-vet / rangeloop-pointer-findings

Issue tracker collects instances of Go code on GitHub that make use of references to range loop variables.
0 stars 0 forks source link

kpmy/rng: loader/tool.go; 3 LoC #3891

Open githubvet opened 3 years ago

githubvet commented 3 years ago

Found a possible issue in kpmy/rng at loader/tool.go

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.

function call which takes a reference to v at line 86 may start a goroutine

Click here to see the code in its original context.

Click here to show the 3 line(s) of Go which triggered the analyzer. ```go for _, v := range n.Inner { do(w, &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 for more information.

commit ID: a294106953f4aafb0816cca6a28591093fbe91fc

kalexmills commented 3 years ago

@Mdempsky I might have something to learn here. It's not clear to me that this one is mitigated because it would depend on what do does with the reference. It's hard to say because it depends on what the caller passes.

Or is there some language nuance I'm missing that applies in this case?

mdempsky commented 3 years ago

Perhaps it's ambiguous to me the scope of "could lead to undesirable behavior". I looked at the package as a whole, and as far as I could tell, it doesn't provide any exported API that could lead to the reference leaking and causing problems. I took that as "it is handled in such a way that no undesirable behavior can occur" under the bucketing categories.

kalexmills commented 3 years ago

I looked at the package as a whole, and as far as I could tell, it doesn't provide any exported API that could lead to the reference leaking and causing problems.

That's good enough for me, thanks! I missed this was a private API. Sorry for calling you out.