Skip to content

Allow configuration of sa5011 checks for custom exit functions #1651

@Brian-McM

Description

@Brian-McM

Summary

Currently, the sa5011 check flags possible nil pointer dereferences even when custom exit functions (such as those provided by custom fatal logging interfaces) are called, making it difficult to use these safely with custom logging or error handling mechanisms.

Proposal

Allow configuration of the sa5011 analyzer to recognize user-specified custom exit functions, similar to how standard log.Fatal or os.Exit are handled.
Provide a mechanism for users to supply a list of fully-qualified function names that should be treated as terminating the program's execution, thus suppressing false positives for nil pointer dereference warnings after those calls.

Motivation
Many codebases use custom logging or error handling interfaces that terminate the application, but these are not recognized by static analysis as exit points.
This feature would reduce false positives, improve analyzer usability, and make static checks more accurate in real-world Go projects.

Example

func (l *Logger) Fatalf(format string, args ...interface{}) {
    // custom logic then os.Exit(1)
}

if obj == nil {
    logger.Fatalf("object is nil")  // should not flag nil dereference after this
}
obj.DoSomething()  // currently flagged by sa5011, should not be if Fatalf is registered as an exit function

Acceptance Criteria

  • Users can configure sa5011 with custom exit functions via config.
  • Analyzer correctly suppresses nil dereference warnings after recognized exit functions.
  • Documentation updated to describe the configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions