Skip to content

Commit d69e584

Browse files
committed
JS: fix bug in foldedComparisonEdge
1 parent 8fd3a41 commit d69e584

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

javascript/ql/src/semmle/javascript/RangeAnalysis.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ module RangeAnalysis {
464464
exists (DataFlow::Node k, int ksign, Bias bias, int avalue, int kvalue |
465465
comparisonEdge(cfg, a, asign, k, ksign, bias, sharp) and
466466
avalue = a.asExpr().getIntValue() * asign and
467-
kvalue = b.asExpr().getIntValue() * bsign and
468-
(avalue < kvalue + bias or sharp = true and avalue = kvalue + bias) and
467+
kvalue = k.asExpr().getIntValue() * ksign and
468+
(avalue > kvalue + bias or sharp = true and avalue = kvalue + bias) and
469469
a = b and
470470
asign = bsign and
471471
c = -1)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function f(arr) {
2+
if (arr.length > 2) {} // OK
3+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
| example.js:8:7:8:13 | i < end | The condition 'i < end' is always false |
1+
| constant.js:2:7:2:11 | 1 > 2 | The condition '1 > 2' is always false. |
2+
| constant.js:3:7:3:11 | 1 > 0 | The condition '1 > 0' is always true. |
3+
| example.js:8:7:8:13 | i < end | The condition 'i < end' is always false. |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function f() {
2+
if (1 > 2) {} else {} // NOT OK - always false
3+
if (1 > 0) {} else {} // NOT OK - always true
4+
}

0 commit comments

Comments
 (0)