Debian Codegraph @

staticcheck/sa9007/testdata/go1.0/CheckBadRemoveAll/CheckBadRemoveAll.go

raw
1 package pkg
2
3 import (
4 "os"
5 "path/filepath"
6 )
7
8 func fn1() {
9 x := os.TempDir()
10 defer os.RemoveAll(x) //@ diag(`deletes the user's entire temporary directory`)
11
12 x = ""
13 }
14
15 func fn2() {
16 x := os.TempDir()
17 if true {
18 os.RemoveAll(x) //@ diag(`deletes the user's entire temporary directory`)
19 }
20 }
21
22 func fn3() {
23 x := os.TempDir()
24 if true {
25 x = filepath.Join(x, "foo")
26 }
27 // we don't flag this to avoid false positives in infeasible paths
28 os.RemoveAll(x)
29 }
30
31 func fn4() {
32 x, _ := os.UserCacheDir()
33 os.RemoveAll(x) //@ diag(`deletes the user's entire cache directory`)
34
35 x, _ = os.UserConfigDir()
36 os.RemoveAll(x) //@ diag(`deletes the user's entire config directory`)
37
38 x, _ = os.UserHomeDir()
39 os.RemoveAll(x) //@ diag(`deletes the user's entire home directory`)
40 }