-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathCouldBeCast.ql
More file actions
27 lines (25 loc) · 984 Bytes
/
CouldBeCast.ql
File metadata and controls
27 lines (25 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* @name Expression can be replaced with a cast
* @description An exists/any that is only used to cast a value to a type
* can be replaced with a cast.
* @kind problem
* @problem.severity warning
* @id ql/could-be-cast
* @precision very-high
*/
import ql
import codeql_ql.style.CouldBeCastQuery
from AstNode aggr, VarDecl var, string msg, Expr operand
where
exists(string kind | aggregateCouldBeCast(aggr, _, kind, var, operand) |
kind = "exists" and
if operand.getType().getASuperType*() = var.getType()
then msg = "The assignment in the exists(..) is redundant."
else msg = "The assignment to $@ in the exists(..) can replaced with an instanceof expression."
or
kind = "any" and
if operand.getType().getASuperType*() = var.getType()
then msg = "The assignment in the any(..) is redundant."
else msg = "The assignment to $@ in this any(..) can be replaced with an inline cast."
)
select aggr, msg, var, var.getName()