Skip to content

Commit

Permalink
added a fix for FPs found by anonymous-race-condition (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
hex0punk authored Jul 14, 2023
1 parent f3a83ba commit a13c350
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions go/anonymous-race-condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,36 @@ func AnonRaceCond_4_FP() {

wg.Wait()
}


func AnonRaceCond_5() {
var wg sync.WaitGroup
// ok: anonymous-race-condition
for idx, val := range values {
wg.Add(1)
idx, val := idx, val
go func() {
val.s.Method("test")
fmt.Println("Completed index", idx)
wg.Done()
}()
}

wg.Wait()
}

func AnonRaceCond_6() {
var wg sync.WaitGroup
// ok: anonymous-race-condition
for idx, val := range values {
wg.Add(1)
idx, val := idx, val
go func() {
fmt.Println(val.s)
fmt.Println("Completed index", idx)
wg.Done()
}()
}

wg.Wait()
}
20 changes: 20 additions & 0 deletions go/anonymous-race-condition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,23 @@ rules:
}(...)
...
}
- pattern-not: |
for $Y, $X := range ... {
...
$Y, $X := $Y, $X
...
go func(...){
...
<... $X.$VAR ...>
}(...)
}
- pattern-not: |
for $Y, $X := range ... {
...
$Y, $X := $Y, $X
...
go func(...){
...
<... $Y.$VAR ...>
}(...)
}

0 comments on commit a13c350

Please sign in to comment.