File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 16
16
import cpp
17
17
import codingstandards.cpp.misra
18
18
import codingstandards.cpp.BannedFunctions
19
+ import codingstandards.cpp.types.Uses
19
20
20
21
class CSetJmpHeader extends Include {
21
22
CSetJmpHeader ( ) { this .getIncludeText ( ) .regexpMatch ( "[<\\\"](csetjmp|setjmp.h)[>\\\"]" ) }
22
23
}
23
24
24
- class JmpBufVariable extends Variable {
25
- JmpBufVariable ( ) { this . getType ( ) . ( UserType ) .hasGlobalOrStdName ( "jmp_buf" ) }
25
+ class JmpBufType extends UserType {
26
+ JmpBufType ( ) { this .hasGlobalOrStdName ( "jmp_buf" ) }
26
27
}
27
28
28
29
class LongjmpFunction extends Function {
39
40
(
40
41
message = "Use of banned header " + element .( CSetJmpHeader ) .getIncludeText ( ) + "."
41
42
or
42
- message =
43
- "Declaration of variable '" + element .( JmpBufVariable ) .getName ( ) +
44
- "' with banned type 'jmp_buf'."
43
+ (
44
+ element = getATypeUse ( any ( JmpBufType jbt ) ) and
45
+ if element instanceof Variable
46
+ then
47
+ message =
48
+ "Declaration of variable '" + element .( Variable ) .getName ( ) +
49
+ "' with banned type 'jmp_buf'."
50
+ else message = "Use of banned type 'jmp_buf'."
51
+ )
45
52
or
46
53
message =
47
54
element .( BannedFunctions< LongjmpFunction > :: Use ) .getAction ( ) + " banned function '" +
Original file line number Diff line number Diff line change 12
12
| test.cpp:21:5:21:16 | call to longjmp | Call to banned function 'longjmp'. |
13
13
| test.cpp:26:11:26:12 | l1 | Declaration of variable 'l1' with banned type 'jmp_buf'. |
14
14
| test.cpp:27:16:27:17 | l2 | Declaration of variable 'l2' with banned type 'jmp_buf'. |
15
+ | test.cpp:40:38:40:39 | l1 | Declaration of variable 'l1' with banned type 'jmp_buf'. |
Original file line number Diff line number Diff line change @@ -35,4 +35,6 @@ void test_compliant_alternative() {
35
35
} catch (const std::runtime_error &) { // COMPLIANT
36
36
// Handle error properly
37
37
}
38
- }
38
+ }
39
+
40
+ void test_jmp_buf_usage () { jmp_buf *l1; } // NON_COMPLIANT - pointer to jmp_buf
You can’t perform that action at this time.
0 commit comments