Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09ca665

Browse files
committed
JS: Support return value of x++
1 parent 73cbdee commit 09ca665

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ module RangeAnalysis {
163163
else
164164
bias = -1)
165165
or
166+
exists (UpdateExpr update | r.asExpr() = update | // Return value of x++ is just x (coerced to an int)
167+
root = update.getOperand().flow() and
168+
not update.isPrefix() and
169+
sign = 1 and
170+
bias = 0)
171+
or
166172
exists (CompoundAssignExpr assign | r = compoundAssignResult(assign) |
167173
root = assign.getLhs().flow() and
168174
sign = 1 and

javascript/ql/test/library-tests/RangeAnalysis/plus.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ function g(x) {
2626
if (z < x + 5) {} // NOT OK - always true
2727
if (z > x + 5) {} // NOT OK - always false
2828
}
29+
30+
function h(x) {
31+
let y = x++;
32+
if (x > y) {} // NOT OK - always true
33+
}

0 commit comments

Comments
 (0)