Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Analyzer = SCAnalyzer.Analyzer
View Source
var SCAnalyzer = lint.InitializeAnalyzer(&lint.Analyzer{ Analyzer: &analysis.Analyzer{ Name: "SA5011", Run: run, Requires: []*analysis.Analyzer{buildir.Analyzer}, }, Doc: &lint.RawDocumentation{ Title: `Possible nil pointer dereference`, Text: `A pointer is being dereferenced unconditionally, while also being checked against nil in another place. This suggests that the pointer may be nil and dereferencing it may panic. This is commonly a result of improperly ordered code or missing return statements. Consider the following examples: func fn(x *int) { fmt.Println(*x) // This nil check is equally important for the previous dereference if x != nil { foo(*x) } } func TestFoo(t *testing.T) { x := compute() if x == nil { t.Errorf("nil pointer received") } // t.Errorf does not abort the test, so if x is nil, the next line will panic. foo(*x) } Staticcheck tries to deduce which functions abort control flow. For example, it is aware that a function will not continue execution after a call to \'panic\' or \'log.Fatal\'. However, sometimes this detection fails, in particular in the presence of conditionals. Consider the following example: func Log(msg string, level int) { fmt.Println(msg) if level == levelFatal { os.Exit(1) } } func Fatal(msg string) { Log(msg, levelFatal) } func fn(x *int) { if x == nil { Fatal("unexpected nil pointer") } fmt.Println(*x) } Staticcheck will flag the dereference of \'x\', even though it is perfectly safe. Staticcheck is not able to deduce that a call to Fatal will exit the program. For the time being, the easiest workaround is to modify the definition of Fatal like so: func Fatal(msg string) { Log(msg, levelFatal) panic("unreachable") } We also hard-code functions from common logging packages such as logrus. Please file an issue if we're missing support for a popular package.`, Since: "2020.1", Severity: lint.SeverityWarning, MergeIf: lint.MergeIfAny, }, })
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.