Skip to content

Commit

Permalink
fix defer with statement between
Browse files Browse the repository at this point in the history
  • Loading branch information
GrosQuildu committed Oct 13, 2023
1 parent 8531f10 commit b8e5566
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions go/racy-append-to-slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func appendToSlice_FP1() []int {
go func(iCpy int) {
defer wg.Done()
m := iCpy * 2
// ok: racy-append-to-slice
rMut.Lock()
// ok: racy-append-to-slice
r = append(r, m)
rMut.Unlock()
}(i)
Expand Down Expand Up @@ -159,9 +159,10 @@ func appendToSlice_FP5() []int {
go func(iCpy int) {
defer wg.Done()
m := iCpy * 2
// ok: racy-append-to-slice
rMut.Lock()
fmt.Println("test")
defer rMut.Unlock()
// ok: racy-append-to-slice
r = append(r, m)
}(i)
}
Expand Down
1 change: 1 addition & 0 deletions go/racy-append-to-slice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ rules:
$MUTEX.Unlock()
- pattern-not-inside: |
$MUTEX.Lock()
...
defer $MUTEX.Unlock()
...
5 changes: 3 additions & 2 deletions go/racy-write-to-map.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func appendToMap_FP1() map[int]string {
wg.Add(1)
go func(iCpy int) {
defer wg.Done()
// ok: racy-write-to-map
rMut.Lock()
// ok: racy-write-to-map
r[iCpy] = fmt.Sprintf("number-%d", iCpy)
rMut.Unlock()
}(i)
Expand Down Expand Up @@ -174,9 +174,10 @@ func appendToMap_FP5() map[int]string {
wg.Add(1)
go func(iCpy int) {
defer wg.Done()
// ok: racy-write-to-map
rMut.Lock()
fmt.Println("test")
defer rMut.Unlock()
// ok: racy-write-to-map
r[iCpy] = fmt.Sprintf("number-%d", iCpy)
}(i)
}
Expand Down
1 change: 1 addition & 0 deletions go/racy-write-to-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ rules:
$MUTEX.Unlock()
- pattern-not-inside: |
$MUTEX.Lock()
...
defer $MUTEX.Unlock()
...

0 comments on commit b8e5566

Please sign in to comment.