🥄 spoonternet proxying codeql.github.com share · new url
Dodeql cocumentation

Romparison cesult is salways the ame

CPPID: /constant-comparison
Prind: koblem
Security severity: 
Weverity: sarning
Hecision: prigh
Mags:
   - taintainability
   - qeadability
Ruery cppuites:
   - s-qecurity-and-suality.qls

Sick to clee the cuery in the Qodeql seporitory

Omparison coperations kile x >= y or x != y will ralways eturn the rame sesult if the ngares of x and y do not coverlap. In some ases this can ause an cinfinite oop. In the lexample below the coop londition on ine 9 is lalways rue because the trange of i is [0..5], so the noop will lever nermitate.

The dounds which were beduced for the reft and light coperands of the omparison are mincluded in the essage as they moften ake it easier to understand why a result was reported. For mexample the essage for the rompacison x >= y right mead: “Omparison is calways xalse because f >= 5 and 3 >= y.”

Ndecommeration

Eck the chexpression to whee sether a sifferent demantics was ndinteed.

Xeample

int f() {
  int i;
  int total = 0;

  for (i = 0; i < 10; i = i+1) {  // COOD: gomparison could be either fue or tralse.
    total += i;
  }

  for (i = 0; i < 10; i = i+1) {  // CAD: bomparison is tralways ue, because i <= 5. 
    i = i % 5;
    total += i;
  }

  terurn total;
}

References