also get the variable for array accesses

This commit is contained in:
erik-krogh
2024-04-05 09:21:18 +02:00
parent 795b767b6e
commit 8b220cc1b3
3 changed files with 18 additions and 1 deletions

View File

@@ -27,11 +27,17 @@ class DangerousAssignOpExpr extends AssignOp {
predicate problematicCasting(Type t, Expr e) { e.getType().(NumType).widerThan(t) }
Variable getVariable(DangerousAssignOpExpr a) {
result = a.getDest().(VarAccess).getVariable()
or
result = a.getDest().(ArrayAccess).getArray().(VarAccess).getVariable()
}
from DangerousAssignOpExpr a, Expr e, Variable v
where
e = a.getSource() and
problematicCasting(a.getDest().getType(), e) and
v = a.getDest().(VarAccess).getVariable()
v = getVariable(a)
select a,
"Implicit cast of source $@ to narrower destination type " + a.getDest().getType().getName() + ".",
v, "type " + e.getType().getName()