File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616import cpp
1717import codingstandards.cpp.misra
1818import codingstandards.cpp.BannedFunctions
19+ import codingstandards.cpp.types.Uses
1920
2021class CSetJmpHeader extends Include {
2122 CSetJmpHeader ( ) { this .getIncludeText ( ) .regexpMatch ( "[<\\\"](csetjmp|setjmp.h)[>\\\"]" ) }
2223}
2324
24- class JmpBufVariable extends Variable {
25- JmpBufVariable ( ) { this . getType ( ) . ( UserType ) .hasGlobalOrStdName ( "jmp_buf" ) }
25+ class JmpBufType extends UserType {
26+ JmpBufType ( ) { this .hasGlobalOrStdName ( "jmp_buf" ) }
2627}
2728
2829class LongjmpFunction extends Function {
3940 (
4041 message = "Use of banned header " + element .( CSetJmpHeader ) .getIncludeText ( ) + "."
4142 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+ )
4552 or
4653 message =
4754 element .( BannedFunctions< LongjmpFunction > :: Use ) .getAction ( ) + " banned function '" +
Original file line number Diff line number Diff line change 1212| test.cpp:21:5:21:16 | call to longjmp | Call to banned function 'longjmp'. |
1313| test.cpp:26:11:26:12 | l1 | Declaration of variable 'l1' with banned type 'jmp_buf'. |
1414| 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() {
3535 } catch (const std::runtime_error &) { // COMPLIANT
3636 // Handle error properly
3737 }
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