mirror of
https://github.com/mgechev/revive.git
synced 2024-11-28 08:49:11 +02:00
3bac05c7a4
range-val-address: improve detection
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package fixtures
|
|
|
|
func rangeValAddress() {
|
|
m := map[string]*string{}
|
|
|
|
mySlice := []string{"A", "B", "C"}
|
|
for _, value := range mySlice {
|
|
m["address"] = &value // MATCH /suspicious assignment of 'value'. range-loop variables always have the same address/
|
|
}
|
|
}
|
|
|
|
func rangeValAddress2() {
|
|
m := map[string]*string{}
|
|
|
|
mySlice := []string{"A", "B", "C"}
|
|
for i := range mySlice {
|
|
m["address"] = &mySlice[i]
|
|
}
|
|
}
|
|
|
|
func rangeValAddress3() {
|
|
m := map[string]*string{}
|
|
|
|
mySlice := []string{"A", "B", "C"}
|
|
for _, value := range mySlice {
|
|
a := &value // MATCH /suspicious assignment of 'value'. range-loop variables always have the same address/
|
|
m["address"] = a
|
|
}
|
|
}
|
|
|
|
func rangeValAddress4() {
|
|
m := []*string{}
|
|
|
|
mySlice := []string{"A", "B", "C"}
|
|
for _, value := range mySlice {
|
|
m = append(m, &value) // MATCH /suspicious assignment of 'value'. range-loop variables always have the same address/
|
|
}
|
|
}
|
|
|
|
func rangeValAddress5() {
|
|
m := map[*string]string{}
|
|
|
|
mySlice := []string{"A", "B", "C"}
|
|
for _, value := range mySlice {
|
|
m[&value] = value // MATCH /suspicious assignment of 'value'. range-loop variables always have the same address/
|
|
}
|
|
}
|
|
|
|
func rangeValAddress6() {
|
|
type v struct {
|
|
id string
|
|
}
|
|
m := []*string{}
|
|
|
|
mySlice := []v{{id: "A"}, {id: "B"}, {id: "C"}}
|
|
for _, value := range mySlice {
|
|
m = append(m, &value.id) // MATCH /suspicious assignment of 'value'. range-loop variables always have the same address/
|
|
}
|
|
}
|