Skip to content

Commit f8805eb

Browse files
committed
Java: Update 2 queries.
1 parent 4bd332d commit f8805eb

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

java/ql/src/Likely Bugs/Arithmetic/MultiplyRemainder.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
import java
1414

15-
from MulExpr e
15+
from MulExpr e, RemExpr lhs
1616
where
17-
e.getLeftOperand() instanceof RemExpr and
17+
e.getLeftOperand() = lhs and
18+
not lhs.isParenthesized() and
1819
e.getRightOperand().getType().hasName("int")
1920
select e, "Result of a remainder operation multiplied by an integer."

java/ql/src/Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,24 @@ predicate endOfBinaryLhs(BinaryExpr expr, int line, int col) {
120120
)
121121
}
122122

123+
/** Compute the number of parenthesis characters next to the operator. */
124+
int getParensNextToOp(BinaryExpr expr) {
125+
exists(Expr left, Expr right, int pleft, int pright |
126+
left = expr.getLeftOperand() and
127+
right = expr.getRightOperand() and
128+
(if left.isParenthesized() then isParenthesized(left, pleft) else pleft = 0) and
129+
(if right.isParenthesized() then isParenthesized(right, pright) else pright = 0) and
130+
result = pleft + pright
131+
)
132+
}
133+
123134
/** Compute whitespace around the operator. */
124135
int operatorWS(BinaryExpr expr) {
125-
exists(int line, int lcol, int rcol |
136+
exists(int line, int lcol, int rcol, int parens |
126137
endOfBinaryLhs(expr, line, lcol) and
127138
startOfBinaryRhs(expr, line, rcol) and
128-
result = rcol - lcol + 1 - expr.getOp().length()
139+
parens = getParensNextToOp(expr) and
140+
result = rcol - lcol + 1 - expr.getOp().length() - parens
129141
)
130142
}
131143

0 commit comments

Comments
 (0)