55 new issues added in the Go analyzer

55 new issues, consisting of 36 bug risks and 19 antipatterns, have been added.

Some of the new issues that have been added are:

  1. Violation of cgo pointer passing rules
    Attempts to pass a Go chan, map, func, or slice to C, either directly, or via a pointer, array, or struct is not recommended. This is because the values of these types (apart from zero-value) always contain Go pointers, which is not allowed by the cgo pointer passing rules.

  2. Incorrect usage of sync/atomic package
    This issue is raised in case of redundant assignment after calling an atomic.Add* function.

  3. sync.WaitGroup expected as a by-value parameter in a function or method
    Function parameters that are passed by value, are in fact a copy of the original argument. Passing a copy of a sync.WaitGroup is usually not what you’d want to do.

  4. Possibly undesired value being used in goroutine
    Range variables in a loop are reused at each iteration; therefore a goroutine created in a loop will point to the range variable with from the upper scope. This way, the goroutine could use the variable with an undesired value. This rule warns when a range value (or index) is used inside a closure

  5. Method expression can be replaced with method call
    It is simpler to use receiver functions of a type by calling them directly, rather than using selector syntax to select a function and then pass a receiver.

6 Likes