diff --git a/addons/misra.py b/addons/misra.py index 63d98ae19..85257239f 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1163,6 +1163,16 @@ def misra_20_5(data): if directive.str.startswith('#undef '): reportError(directive, 20, 5) +def misra_20_13(data): + for directive in data.directives: + dir = directive.str + if dir.find(' ') > 0: + dir = dir[:dir.find(' ')] + if dir.find('(') > 0: + dir = dir[:dir.find('(')] + if dir not in ['#define', '#elif', '#else', '#endif', '#error', '#if', '#ifdef', '#ifndef', '#include', '#pragma', '#undef', '#warning']: + reportError(directive, 20, 13) + def misra_20_14(data): if1 = [] for directive in data.directives: @@ -1457,6 +1467,7 @@ for arg in sys.argv[1:]: misra_20_3(data.rawTokens) misra_20_4(cfg) misra_20_5(cfg) + misra_20_13(cfg) misra_20_14(cfg) misra_21_3(cfg) misra_21_4(cfg) diff --git a/addons/test/misra-test.c b/addons/test/misra-test.c index 3c7982691..f2944b33d 100644 --- a/addons/test/misra-test.c +++ b/addons/test/misra-test.c @@ -332,6 +332,8 @@ union misra_19_2 { }; // 19.2 #define int short // 20.4 #undef X // 20.5 +#else1 // 20.13 + void misra_21_3() { p1=malloc(10); // 21.3 p2=calloc(10); // 21.3