Skip to content

Commit

Permalink
add link to the source variable in the alert-message for java/implici…
Browse files Browse the repository at this point in the history
…t-cast-in-compound-assignment
  • Loading branch information
erik-krogh committed Apr 8, 2024
1 parent 2256c4c commit 795b767
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions java/ql/src/Likely Bugs/Arithmetic/InformationLoss.ql
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class DangerousAssignOpExpr extends AssignOp {

predicate problematicCasting(Type t, Expr e) { e.getType().(NumType).widerThan(t) }

from DangerousAssignOpExpr a, Expr e
from DangerousAssignOpExpr a, Expr e, Variable v
where
e = a.getSource() and
problematicCasting(a.getDest().getType(), e)
problematicCasting(a.getDest().getType(), e) and
v = a.getDest().(VarAccess).getVariable()
select a,
"Implicit cast of source type " + e.getType().getName() + " to narrower destination type " +
a.getDest().getType().getName() + "."
"Implicit cast of source $@ to narrower destination type " + a.getDest().getType().getName() + ".",
v, "type " + e.getType().getName()
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
| Test.java:68:5:68:25 | ...+=... | Implicit cast of source type long to narrower destination type int. |
| Test.java:87:4:87:9 | ...+=... | Implicit cast of source type long to narrower destination type int. |
| Test.java:68:5:68:25 | ...+=... | Implicit cast of source $@ to narrower destination type int. | Test.java:64:4:64:13 | int i | type long |
| Test.java:87:4:87:9 | ...+=... | Implicit cast of source $@ to narrower destination type int. | Test.java:81:4:81:13 | int i | type long |

0 comments on commit 795b767

Please sign in to comment.