Skip to content

Commit 880c39a

Browse files
remove non-SAL parameters due to false positives
1 parent 335b284 commit 880c39a

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

src/drivers/general/queries/StrictTypeMatch/StrictTypeMatch.ql

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,43 +25,32 @@ import drivers.libraries.SAL
2525
from EnumConstantAccess eca, FunctionCall fc, Parameter p, int i
2626
where
2727
fc.getArgument(i) = eca and
28+
not fc.getTarget().getName().matches("operator new%") and // exclude new operators
2829
p = fc.getTarget().getParameter(i) and
29-
(
30-
// check for pattern __drv_strictType(typename, mode)
31-
if p instanceof SALParameter
32-
then
33-
exists(string enumType1, string enumType2 |
34-
enumType1 = eca.getTarget().getDeclaringEnum().toString() and
35-
enumType2 =
30+
// check for pattern __drv_strictType(typename, mode)
31+
p instanceof SALParameter and
32+
exists(string enumType1, string enumType2 |
33+
enumType1 = eca.getTarget().getDeclaringEnum().toString() and
34+
enumType2 =
35+
p.(SALParameter)
36+
.getAnnotation()
37+
.getUnexpandedArgument(0)
38+
.toString()
39+
.splitAt("/", _)
40+
.replaceAll("enum", "")
41+
.trim() and
42+
not enumType2.matches("__drv_%") and // exclude other SAL annotations
43+
not exists(string allowedType |
44+
allowedType =
3645
p.(SALParameter)
3746
.getAnnotation()
3847
.getUnexpandedArgument(0)
3948
.toString()
4049
.splitAt("/", _)
4150
.replaceAll("enum", "")
4251
.trim() and
43-
not enumType2.matches("__drv_%") and // exclude other SAL annotations
44-
not exists(string allowedType |
45-
allowedType =
46-
p.(SALParameter)
47-
.getAnnotation()
48-
.getUnexpandedArgument(0)
49-
.toString()
50-
.splitAt("/", _)
51-
.replaceAll("enum", "")
52-
.trim() and
53-
allowedType = enumType1
54-
)
52+
allowedType = enumType1
5553
)
56-
else
57-
// non SAL parameter
58-
eca.getTarget().getDeclaringEnum().toString() !=
59-
fc.getTarget()
60-
.getADeclarationEntry()
61-
.getParameterDeclarationEntry(i)
62-
.getType()
63-
.getUnderlyingType()
64-
.toString()
6554
)
6655
select eca,
6756
"Enumerated value in a function call does not match the type specified for the parameter in the function declaration"

0 commit comments

Comments
 (0)