Skip to content

impossible-integer-comparison

Detect integer comparisons fixed by the type's range.

Updated View as Markdown

Default severity: warning

An integer type’s minimum and maximum values make some comparisons always true or false, such as checking whether an unsigned value is below zero or above its maximum. Target-sized int, uint, and uintptr use the loaded build architecture.

Bad

if value < 0 { use() } // value is unsigned

Good

if value == 0 { use() }
Navigation

Type to search…

↑↓ navigate↵ selectEsc close