diff --git a/addons/misra.py b/addons/misra.py index ddbd70638..144f7aa85 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1356,7 +1356,17 @@ class MisraChecker: # ^ ^ end_tokens_map = {} + skip_to = None for token in data.tokenlist: + # Skip tokens in function call body + if skip_to: + if token == skip_to: + skip_to = None + else: + continue + if token.function and token.next and token.next.str == "(": + skip_to = token.next.link + if token.scope.type in ('Enum', 'Class', 'Struct', 'Global'): continue # Save end tokens from function calls in initialization diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index db11bcf10..c6760c878 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -347,8 +347,13 @@ static struct misra_12_3_s1 misra_12_3_s1_inst = { typedef struct misra_12_3_s2 { int a; int b; int c, d; } misra_12_3_s2_t; typedef struct { int a; int b; int c, d; } misra_12_3_s3_t; void misra_12_3_fn1(int, int); static int misra_12_3_v5, misra_12_4_v6; // 12.3 -void misra_12_3_fn2(int a, int b) { int d, e; } // 12.3 2.7 +void misra_12_3_fn2(int a, int b) // 2.7 +{ int d, e; } // 12.3 int misra_12_3_fn3(int a, int b) { return a+b;} static int misra_12_3_v5, misra_12_4_v6; // 12.3 +void misra_12_3_fn4(const uint32_t value, uint8_t * const y) {} // 2.7 +uint32_t misra_12_3_fn5(const uint32_t * const, const uint8_t) {} // 2.7 +extern void misra_12_3_fn6(const uint32_t value, uint8_t * const y); +extern uint32_t misra_12_3_fn7(const uint32_t * const, const uint8_t); #define MISRA_12_3_FN3_1(A, B) (misra_12_3_fn3(A, B)) #define MISRA_12_3_FN3_2(A, B) (misra_12_3_fn3(A, \ B)) @@ -393,6 +398,12 @@ void misra_12_3(int a, int b, int c) { // no warning i < 42; ++i, ++p ) // 12.3 {} + + // No false positives in local and extern function calls + misra_12_3_fn4(misra_12_3_fn5(&a1, 32), &a1); + misra_12_3_fn4(misra_12_3_fn7(&a1, 32), &a1); + misra_12_3_fn6(misra_12_3_fn5(&a1, 32), &a1); + misra_12_3_fn6(misra_12_3_fn7(&a1, 32), &a1); } #define MISRA12_4a 2000000000u