CodeQL documentation

Unsigned comparison to zero

ID: cpp/unsigned-comparison-zero
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - maintainability
   - readability
Query suites:
   - cpp-security-and-quality.qls

Click to see the query in the CodeQL repository

This rule finds expressions of the form x >= 0 where x is an unsigned value. This comparison is pointless as it will always yield 1.

Recommendation

Check the expression to see whether a different semantics was intended.

Example

typedef long long LONGLONG;

int f(unsigned int u, LONGLONG l) {
	if(u > 0 || l >=0)       //correct: unsigned value is check for > 0
		return 23;
	return u >= 0;           //wrong: unsigned values are always greater than or equal to 0
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy