-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iterate-over-empty-map
warning on map initialised at the declaration
#36
Comments
Interesting. Looks like Semgrep coerces - pattern: |
$C = map[$T1] $T2{...} - pattern: |
$C = make(map[$T1] $T2, ...) func main() {
m := make(map[string]int)
m2 := map[string]int{}
m3 := map[string]int{"a":1}
} Will report that upstream, unless @Vasco-jofra has some thoughts here. |
Waiting for upstream fix. More tests for the future: func iter1_2(){
// ruleid: iterate-over-empty-map
m := make(map[string]int, 5)
for v := range m {
fmt.Println("map item: ", v)
}
}
func iter1_3(){
// ruleid: iterate-over-empty-map
m := map[string]int{}
for v := range m {
fmt.Println("map item: ", v)
}
}
func iter1_FP_5(){
// ok: iterate-over-empty-map
m := make(map[string]int, 1)
m["v1"]--
for v := range m {
fmt.Println("map item: ", v)
}
}
func iter1_FP_6(){
// ok: iterate-over-empty-map
m := map[string]int{"test": 1}
for v := range m {
fmt.Println("map item: ", v)
}
} |
I just ran into this too. I wrote a test here so we'll know when this is fixed upstream: #62 The above issue is very similar, or a dupe of semgrep/semgrep#9558 |
Hello,
I'm struggling to understand why the following code function has a
iterate-over-empty-map
:Could you help me with that? 🙏
cc @Caomoji
The text was updated successfully, but these errors were encountered: