-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathIncompatibleFunctionDeclarations.ql
More file actions
62 lines (57 loc) · 2.18 KB
/
IncompatibleFunctionDeclarations.ql
File metadata and controls
62 lines (57 loc) · 2.18 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @id c/cert/incompatible-function-declarations
* @name DCL40-C: Do not create incompatible declarations of the same function or object
* @description Declaring incompatible functions, in other words same named function of different
* return types or with different numbers of parameters or parameter types, then
* accessing those functions can lead to undefined behaviour.
* @kind problem
* @precision high
* @problem.severity error
* @tags external/cert/id/dcl40-c
* correctness
* maintainability
* readability
* external/cert/severity/low
* external/cert/likelihood/unlikely
* external/cert/remediation-cost/medium
* external/cert/priority/p2
* external/cert/level/l3
* external/cert/obligation/rule
*/
import cpp
import codingstandards.c.cert
import codingstandards.cpp.types.Compatible
import ExternalIdentifiers
predicate interestedInFunctions(
FunctionDeclarationEntry f1, FunctionDeclarationEntry f2, ExternalIdentifiers d
) {
not f1 = f2 and
d = f1.getDeclaration() and
d = f2.getDeclaration()
}
predicate interestedInFunctions(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
interestedInFunctions(f1, f2, _)
}
module FuncDeclEquiv =
FunctionDeclarationTypeEquivalence<TypesCompatibleConfig, interestedInFunctions/2>;
from ExternalIdentifiers d, FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
where
not isExcluded(f1, Declarations2Package::incompatibleFunctionDeclarationsQuery()) and
not isExcluded(f2, Declarations2Package::incompatibleFunctionDeclarationsQuery()) and
interestedInFunctions(f1, f2, d) and
(
//return type check
not FuncDeclEquiv::equalReturnTypes(f1, f2)
or
//parameter type check
not FuncDeclEquiv::equalParameterTypes(f1, f2)
) and
// Apply ordering on start line, trying to avoid the optimiser applying this join too early
// in the pipeline
exists(int f1Line, int f2Line |
f1.getLocation().hasLocationInfo(_, f1Line, _, _, _) and
f2.getLocation().hasLocationInfo(_, f2Line, _, _, _) and
f1Line >= f2Line
)
select f1, "The object $@ is not compatible with re-declaration $@", f1, f1.getName(), f2,
f2.getName()