Skip to content

Commit 1e95a5a

Browse files
committed
Java: Consider AssignOps in ArithExpr
1 parent c45ca72 commit 1e95a5a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Improved the class `ArithExpr` of the `Overflow.qll` module to also include compound operators. Because of this, new alerts may be raised in queries related to overflows/underflows.

java/ql/lib/semmle/code/java/arithmetic/Overflow.qll

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,19 @@ class ArithExpr extends Expr {
8080
(
8181
this instanceof UnaryAssignExpr or
8282
this instanceof AddExpr or
83+
this instanceof AssignAddExpr or
8384
this instanceof MulExpr or
85+
this instanceof AssignMulExpr or
8486
this instanceof SubExpr or
85-
this instanceof DivExpr
87+
this instanceof AssignSubExpr or
88+
this instanceof DivExpr or
89+
this instanceof AssignDivExpr
8690
) and
87-
forall(Expr e | e = this.(BinaryExpr).getAnOperand() or e = this.(UnaryAssignExpr).getExpr() |
91+
forall(Expr e |
92+
e = this.(BinaryExpr).getAnOperand() or
93+
e = this.(UnaryAssignExpr).getExpr() or
94+
e = this.(AssignOp).getSource()
95+
|
8896
e.getType() instanceof NumType
8997
)
9098
}
@@ -103,17 +111,21 @@ class ArithExpr extends Expr {
103111
*/
104112
Expr getLeftOperand() {
105113
result = this.(BinaryExpr).getLeftOperand() or
106-
result = this.(UnaryAssignExpr).getExpr()
114+
result = this.(UnaryAssignExpr).getExpr() or
115+
result = this.(AssignOp).getDest()
107116
}
108117

109118
/**
110119
* Gets the right-hand operand if this is a binary expression.
111120
*/
112-
Expr getRightOperand() { result = this.(BinaryExpr).getRightOperand() }
121+
Expr getRightOperand() {
122+
result = this.(BinaryExpr).getRightOperand() or result = this.(AssignOp).getRhs()
123+
}
113124

114125
/** Gets an operand of this arithmetic expression. */
115126
Expr getAnOperand() {
116127
result = this.(BinaryExpr).getAnOperand() or
117-
result = this.(UnaryAssignExpr).getExpr()
128+
result = this.(UnaryAssignExpr).getExpr() or
129+
result = this.(AssignOp).getSource()
118130
}
119131
}

0 commit comments

Comments
 (0)