aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/kyoh86/exportloopref/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/kyoh86/exportloopref/README.md')
-rw-r--r--vendor/github.com/kyoh86/exportloopref/README.md55
1 files changed, 49 insertions, 6 deletions
diff --git a/vendor/github.com/kyoh86/exportloopref/README.md b/vendor/github.com/kyoh86/exportloopref/README.md
index 5b1549159..5c019c738 100644
--- a/vendor/github.com/kyoh86/exportloopref/README.md
+++ b/vendor/github.com/kyoh86/exportloopref/README.md
@@ -2,13 +2,14 @@
An analyzer that finds exporting pointers for loop variables.
+[![PkgGoDev](https://pkg.go.dev/badge/kyoh86/exportloopref)](https://pkg.go.dev/kyoh86/exportloopref)
[![Go Report Card](https://goreportcard.com/badge/github.com/kyoh86/exportloopref)](https://goreportcard.com/report/github.com/kyoh86/exportloopref)
[![Coverage Status](https://img.shields.io/codecov/c/github/kyoh86/exportloopref.svg)](https://codecov.io/gh/kyoh86/exportloopref)
[![Release](https://github.com/kyoh86/exportloopref/workflows/Release/badge.svg)](https://github.com/kyoh86/exportloopref/releases)
## What's this?
-Sample problem code from: https://github.com/kyoh86/exportloopref/blob/master/testdata/simple/simple.go
+Sample problem code from: https://github.com/kyoh86/exportloopref/blob/master/testdata/src/simple/simple.go
```go
package main
@@ -32,8 +33,8 @@ func main() {
var vArray [4]*int
var v *int
if i%2 == 0 {
- v = &p // not a diagnostic (x is inner variable)
- vArray[1] = &p // not a diagnostic (x is inner variable)
+ v = &p // not a diagnostic (x is local variable)
+ vArray[1] = &p // not a diagnostic (x is local variable)
vStr.x = &p
}
_ = v
@@ -72,7 +73,7 @@ func main() {
println("loop expecting 10, 11, 12, 13")
for i, p := range []int{10, 11, 12, 13} {
- p := p // FIX variable into the inner variable
+ p := p // FIX variable into the local variable
printp(&p)
intSlice = append(intSlice, &p)
intArray[i] = &p
@@ -108,12 +109,12 @@ func printp(p *int) {
}
```
-ref: https://github.com/kyoh86/exportloopref/blob/master/testdata/fixed/fixed.go
+ref: https://github.com/kyoh86/exportloopref/blob/master/testdata/src/fixed/fixed.go
## Sensing policy
I want to make exportloopref as accurately as possible.
-So some cases of lints will be ignored.
+So some cases of lints will be false-negative.
e.g.
@@ -127,6 +128,48 @@ for _, p := []int{10, 11, 12, 13} {
If you want to report all of lints (with some false-positives),
you should use [looppointer](https://github.com/kyoh86/looppointer).
+### Known false negatives
+
+Case 1: pass the pointer to function to export.
+
+Case 2: pass the pointer to local variable, and export it.
+
+```go
+package main
+
+type List []*int
+
+func (l *List) AppendP(p *int) {
+ *l = append(*l, p)
+}
+
+func main() {
+ var slice []*int
+ list := List{}
+
+ println("loop expect exporting 10, 11, 12, 13")
+ for _, v := range []int{10, 11, 12, 13} {
+ list.AppendP(&v) // Case 1: wanted "exporting a pointer for the loop variable v", but cannot be found
+
+ p := &v // p is the local variable
+ slice = append(slice, p) // Case 2: wanted "exporting a pointer for the loop variable v", but cannot be found
+ }
+
+ println(`slice expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
+ for _, p := range slice {
+ printp(p)
+ }
+ println(`array expecting "10, 11, 12, 13" but "13, 13, 13, 13"`)
+ for _, p := range ([]*int)(list) {
+ printp(p)
+ }
+}
+
+func printp(p *int) {
+ println(*p)
+}
+```
+
## Install
go: