ATH-cmp-unsign-neg
In this section:
Synopsis
An unsigned value is compared to see whether it is negative.
Enabled by default
Yes
Severity/Certainty
Low/High

Full description
A comparison is performed on an unsigned value, to see whether it is negative. This comparison always returns false, and is redundant.
Coding standards
- CWE 570
Expression is Always False
Code examples
The following code example fails the check and will give a warning:
int foo(unsigned int x)
{
if (x < 0) //checking an unsigned for negativity
return 1;
else
return 0;
}
The following code example passes the check and will not give a warning about this issue:
int foo(unsigned int x)
{
if (x < 1) //OK - x might be 0
return 1;
else
return 0;
}