mirror of
https://github.com/github/codeql.git
synced 2026-03-31 04:38:18 +02:00
Merge pull request #21412 from aschackmull/java/binary-assignment
Java: Make Assignment extend BinaryExpr.
This commit is contained in:
@@ -19,6 +19,7 @@ where
|
||||
lit.getLiteral() = val and
|
||||
val.regexpMatch("0[0-7][0-7]+") and
|
||||
lit.getParent() instanceof BinaryExpr and
|
||||
not lit.getParent() instanceof Assignment and
|
||||
not lit.getParent() instanceof BitwiseExpr and
|
||||
not lit.getParent() instanceof ComparisonExpr
|
||||
select lit, "Integer literal starts with 0."
|
||||
|
||||
@@ -138,13 +138,14 @@ int operatorWS(BinaryExpr expr) {
|
||||
endOfBinaryLhs(expr, line, lcol) and
|
||||
startOfBinaryRhs(expr, line, rcol) and
|
||||
parens = getParensNextToOp(expr) and
|
||||
result = rcol - lcol + 1 - expr.getOp().length() - parens
|
||||
result = rcol - lcol - 1 - expr.getOp().length() - parens
|
||||
)
|
||||
}
|
||||
|
||||
/** Find nested binary expressions where the programmer may have made a precedence mistake. */
|
||||
predicate interestingNesting(BinaryExpr inner, BinaryExpr outer) {
|
||||
inner = outer.getAChildExpr() and
|
||||
not outer instanceof Assignment and
|
||||
not inner instanceof AssocNestedExpr and
|
||||
not inner instanceof HarmlessNestedExpr and
|
||||
not inner.isParenthesized()
|
||||
|
||||
@@ -58,6 +58,7 @@ predicate equal(Expr left, Expr right) {
|
||||
sameVariable(left, right, _)
|
||||
or
|
||||
exists(BinaryExpr bLeft, BinaryExpr bRight | bLeft = left and bRight = right |
|
||||
not bLeft instanceof Assignment and
|
||||
bLeft.getKind() = bRight.getKind() and
|
||||
equal(bLeft.getLeftOperand(), bRight.getLeftOperand()) and
|
||||
equal(bLeft.getRightOperand(), bRight.getRightOperand())
|
||||
|
||||
@@ -101,17 +101,10 @@ Expr overFlowCand() {
|
||||
|
|
||||
bin instanceof AddExpr or
|
||||
bin instanceof MulExpr or
|
||||
bin instanceof LeftShiftExpr
|
||||
)
|
||||
or
|
||||
exists(AssignOp op |
|
||||
result = op and
|
||||
positive(op.getDest()) and
|
||||
positive(op.getRhs())
|
||||
|
|
||||
op instanceof AssignAddExpr or
|
||||
op instanceof AssignMulExpr or
|
||||
op instanceof AssignLeftShiftExpr
|
||||
bin instanceof LeftShiftExpr or
|
||||
bin instanceof AssignAddExpr or
|
||||
bin instanceof AssignMulExpr or
|
||||
bin instanceof AssignLeftShiftExpr
|
||||
)
|
||||
or
|
||||
exists(AddExpr add, CompileTimeConstantExpr c |
|
||||
|
||||
@@ -36,6 +36,7 @@ Variable flowTarget(Expr arg) {
|
||||
*/
|
||||
predicate unboxed(BoxedExpr e) {
|
||||
exists(BinaryExpr bin | e = bin.getAnOperand() |
|
||||
not bin instanceof Assignment and
|
||||
if bin instanceof EqualityTest or bin instanceof ComparisonExpr
|
||||
then bin.getAnOperand() instanceof PrimitiveExpr
|
||||
else bin instanceof PrimitiveExpr
|
||||
|
||||
Reference in New Issue
Block a user