-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathExceptionHandlingFeaturesOfFenvhUsed.ql
More file actions
53 lines (49 loc) · 1.66 KB
/
ExceptionHandlingFeaturesOfFenvhUsed.ql
File metadata and controls
53 lines (49 loc) · 1.66 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
/**
* @id c/misra/exception-handling-features-of-fenvh-used
* @name RULE-21-12: The exception handling features of 'fenv.h' should not be used
* @description The use of the exception handling features of 'fenv.h' may result in undefined
* behavior.
* @kind problem
* @precision very-high
* @problem.severity warning
* @tags external/misra/id/rule-21-12
* correctness
* external/misra/obligation/advisory
*/
import cpp
import codingstandards.c.misra
class FPExceptionHandlingFunction extends Function {
FPExceptionHandlingFunction() {
this.hasName([
"feclearexcept", "fegetexceptflag", "feraiseexcept", "fesetexceptflag", "fetestexcept"
]) and
this.getFile().getBaseName() = "fenv.h"
}
}
class FPExceptionHandlingMacro extends Macro {
FPExceptionHandlingMacro() {
this.hasName([
"FE_INEXACT", "FE_DIVBYZERO", "FE_UNDERFLOW", "FE_OVERFLOW", "FE_INVALID", "FE_ALL_EXCEPT"
]) and
this.getFile().getBaseName() = "fenv.h"
}
}
from Locatable call, string name, string kind
where
not isExcluded(call, BannedPackage::exceptionHandlingFeaturesOfFenvhUsedQuery()) and
(
exists(FPExceptionHandlingFunction f |
call = f.getACallToThisFunction() and
name = f.getName() and
kind = "function"
)
or
exists(FPExceptionHandlingMacro m |
call = m.getAnInvocation() and
name = m.getName() and
kind = "macro" and
// Exclude macro invocations expanded from other macro invocations from macros in fenv.h.
not call.(MacroInvocation).getParentInvocation().getMacro().getFile().getBaseName() = "fenv.h"
)
)
select call, "Call to banned " + kind + " " + name + "."