-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathExceptionHandlingFeaturesOfFenvhUsed.ql
63 lines (59 loc) · 2 KB
/
ExceptionHandlingFeaturesOfFenvhUsed.ql
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
63
/**
* @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/c/2012/amendment2
* external/misra/obligation/advisory
*/
import cpp
import codingstandards.c.misra
class FPExceptionHandlingFunction extends Function {
FPExceptionHandlingFunction() {
this.hasName([
"feclearexcept", "fegetexceptflag", "feraiseexcept", "fesetexceptflag", "fetestexcept",
"fesetenv", "feupdateenv", "fesetround"
]) 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 element, string name, string message
where
not isExcluded(element, BannedPackage::exceptionHandlingFeaturesOfFenvhUsedQuery()) and
(
exists(Include include |
include.getIncludedFile().getBaseName() = "fenv.h" and
message = "Include of banned header" and
name = "fenv.h" and
element = include
)
or
exists(FPExceptionHandlingFunction f |
element = f.getACallToThisFunction() and
name = f.getName() and
message = "Call to banned function"
)
or
exists(FPExceptionHandlingMacro m |
element = m.getAnInvocation() and
name = m.getName() and
message = "Expansion of banned macro" and
// Exclude macro invocations expanded from other macro invocations from macros in fenv.h.
not element.(MacroInvocation).getParentInvocation().getMacro().getFile().getBaseName() =
"fenv.h"
)
)
select element, message + " '" + name + "'."