Skip to content

Commit 05b570a

Browse files
author
Max Schaefer
committed
Improve inVoidContext to take conditional expressions into account.
1 parent 42ca3f3 commit 05b570a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

javascript/ql/lib/Expressions/ExprHasNoEffect.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ predicate inVoidContext(Expr e) {
3838
)
3939
or
4040
exists(LogicalBinaryExpr logical | e = logical.getRightOperand() and inVoidContext(logical))
41+
or
42+
exists(ConditionalExpr cond | e = cond.getABranch())
4143
}
4244

4345
/**

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
| tst.js:50:3:50:49 | new Syn ... o me?") | This expression has no effect. |
1111
| tst.js:51:3:51:36 | new Err ... age(e)) | This expression has no effect. |
1212
| tst.js:62:2:62:20 | o.trivialNonGetter1 | This expression has no effect. |
13+
| tst.js:78:24:78:24 | o | This expression has no effect. |
1314
| uselessfn.js:1:1:1:15 | (functi ... .");\\n}) | This expression has no effect. |

javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/tst.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,8 @@ function g() {
7373
Object.defineProperty(o, "nonTrivialGetter2", unknownGetterDef());
7474
o.nonTrivialGetter2; // OK
7575

76-
(o: empty); // OK.
76+
(o: empty); // OK
77+
78+
testSomeCondition() ? o : // NOT OK
79+
doSomethingDangerous();
7780
};

0 commit comments

Comments
 (0)