diff --git a/addons/misra.py b/addons/misra.py index 4f37d20413c0..a96c1afa85ba 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -2805,7 +2805,9 @@ def misra_14_4(self, data): continue if not token.astOperand1 or not (token.astOperand1.str in ['if', 'while']): continue - if not isBoolExpression(token.astOperand2): + if isBoolExpression(token.astOperand2): + continue + if token.astOperand2.valueType: self.reportError(token, 14, 4) def misra_15_1(self, data): @@ -3185,6 +3187,17 @@ def misra_17_3(self, cfg): for w in cfg.clang_warnings: if w['message'].endswith('[-Wimplicit-function-declaration]'): self.reportError(cppcheckdata.Location(w), 17, 3) + for token in cfg.tokenlist: + if token.str not in ["while","if"]: + continue + if token.next.str != "(": + continue + tok = token.next + while (tok != token.next.link): + if tok.isName and not tok.function and tok.next.str == "(": + self.reportError(tok, 17, 3) + tok = tok.next + def misra_17_6(self, rawTokens): for token in rawTokens: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 279371d2a37a..c739901a3594 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -67,7 +67,7 @@ static void misra_1_2(void) static _Atomic int misra_1_4_var; // 1.4 static _Noreturn void misra_1_4_func(void) // 1.4 { - if (0 != _Generic(misra_1_4_var)) {} // 1.4 + if (0 != _Generic(misra_1_4_var)) {} // 1.4 17.3 printf_s("hello"); // 1.4 } @@ -160,13 +160,13 @@ static void foo(void) { for(i = 0; i < 10; i++) { - if(misra_5_2_func3()) //14.4 + if(misra_5_2_func3()) //17.3 { int misra_5_2_var_hides_var_1____31x; int misra_5_2_var_hides_var_1____31y;//5.2 } } - } while(misra_5_2_func2()); //14.4 + } while(misra_5_2_func2()); //17.3 } break; } @@ -252,11 +252,11 @@ static void misra_5_5_func1(void) { do { - if(misra_5_5_func3()) //14.4 + if(misra_5_5_func3()) //17.3 { int misra_5_5_hides_macro________31y; //5.5 } - } while(misra_5_5_func2()); //14.4 + } while(misra_5_5_func2()); //17.3 } break; } @@ -1297,13 +1297,16 @@ struct { unsigned int y:1; } r14_4_struct; // 8.4 static void misra_14_4(bool b) { - if (x+4){} // 14.4 + if (x+4){} else {} if (b) {} else {} if (r14_4_struct.x) {} + + // #12079 + if (z) {} } static void misra_15_1(void) {