diff --git a/addons/misra.py b/addons/misra.py index 203283cef..14776e7d6 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -1136,9 +1136,19 @@ class MisraChecker: if token.variable is not None and token.variable in func_param_list: func_param_list.remove(token.variable) token = token.next - if len(func_param_list) > 0: - # At least one parameter has not been referenced in function body - self.reportError(func.tokenDef, 2, 7) + # Emit a warning for each unused variable, but no more that one warning per line + reported_linenrs = set() + for func_param in func_param_list: + if func_param.nameToken: + linenr = func_param.nameToken + if linenr not in reported_linenrs: + self.reportError(func_param.nameToken, 2, 7) + reported_linenrs.add(linenr) + else: + linenr = func.tokenDef.linenr + if linenr not in reported_linenrs: + self.reportError(func.tokenDef, 2, 7) + reported_linenrs.add(linenr) def misra_3_1(self, rawTokens): for token in rawTokens: diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index 39b68c0a2..a2c83cb06 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -65,8 +65,21 @@ void misra_2_7_used_params (int *param1, int param2, int param3) *param1 = param2; } -void misra_2_7_vararg(int a, ...) { (void)a; } -void misra_2_7_unnamed_arg(int) { } // 2.7 8.2 +void misra_2_7_a(int a, + int b, // 2.7 + int c, + int d) // 2.7 +{ + (void)a; + (void)c; +} +void misra_2_7_b(int a, int b, int c, // 2.7 + int d) // 2.7 +{ + (void)a; +} +void misra_2_7_c(int a, ...) { (void)a; } +void misra_2_7_d(int) { } // 2.7 8.2 void misra_3_2(int enable) {