Go

Go

Made by DeepSource

Incomplete condition CRT-D0017

Bug risk
Major
Autofix

Some conditions become unsafe when not exhaustive. It is recommended to introduce complete condition checking to avoid bug risks.

Bad practice

In the following example, the slice xs may be of zero length, but not necessarily nil (say, when xs := make([]SomeType, 0)). Hence, the second part of the condition will panic if there are no elements yet.

xs != nil && xs[0] != nil

Recommended

len(xs) != 0 && xs[0] != nil