Skip to content

negative-length-capacity-comparison

Detect checks for negative len or cap results.

Updated View as Markdown

Default severity: warning

The predeclared len and cap functions always return non-negative values, so testing whether either result is below zero can never succeed.

Bad

if len(values) < 0 { unreachable() }

Good

if len(values) == 0 { handleEmpty() }
Navigation

Type to search…

↑↓ navigate↵ selectEsc close