Cppcheck reports violations of rule 20.7 in two macros of alternative.h. The first one is in the __ALT_PTR macro where cppcheck wants to have parentheses on the second operand of a member access operator, which is not allowed from the c language syntax, furthermore, the macro parameter is never used as an expression, hence we can suppress the finding.
The second finding is in the __ALTERNATIVE_CFG macro, where cppcheck wants to have parentheses on the macro arguments, but the macro parameters are never used as expressions and are used only for text substitution, so cppcheck is not taking into account the context of use of the macro arguments and adding parenthesis would break the code, so we can suppress the finding. No error was shown by eclair and coverity for those lines. Signed-off-by: Luca Fancellu <luca.fance...@arm.com> --- docs/misra/false-positive-cppcheck.json | 14 ++++++++++++++ xen/arch/arm/include/asm/alternative.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/docs/misra/false-positive-cppcheck.json b/docs/misra/false-positive-cppcheck.json index 5d4da2ce6170..5e7d9377f60b 100644 --- a/docs/misra/false-positive-cppcheck.json +++ b/docs/misra/false-positive-cppcheck.json @@ -3,6 +3,20 @@ "content": [ { "id": "SAF-0-false-positive-cppcheck", + "violation-id": "misra-c2012-20.7", + "tool-version": "2.7", + "name": "R20.7 second operand of member-access operator", + "text": "The second operand of a member access operator shall be a name of a member of the type pointed to, so in this particular case it is wrong to use parentheses on the macro parameter." + }, + { + "id": "SAF-1-false-positive-cppcheck", + "violation-id": "misra-c2012-20.7", + "tool-version": "2.7", + "name": "R20.7 C macro parameters used only for text substitution", + "text": "The macro parameters used in this case are not part of an expression, they are used for text substitution." + }, + { + "id": "SAF-2-false-positive-cppcheck", "violation-id": "", "tool-version": "", "name": "Sentinel", diff --git a/xen/arch/arm/include/asm/alternative.h b/xen/arch/arm/include/asm/alternative.h index 1eb4b60fbb3e..9d4dc53bb0c6 100644 --- a/xen/arch/arm/include/asm/alternative.h +++ b/xen/arch/arm/include/asm/alternative.h @@ -20,6 +20,7 @@ struct alt_instr { }; /* Xen: helpers used by common code. */ +/* SAF-0-false-positive-cppcheck R20.7 member-access operator */ #define __ALT_PTR(a,f) ((void *)&(a)->f + (a)->f) #define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset) #define ALT_REPL_PTR(a) __ALT_PTR(a, alt_offset) @@ -58,6 +59,7 @@ int apply_alternatives(const struct alt_instr *start, const struct alt_instr *en * * Alternatives with callbacks do not generate replacement instructions. */ +/* SAF-1-false-positive-cppcheck R20.7 argument for text substitution */ #define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled, cb) \ ".if "__stringify(cfg_enabled)" == 1\n" \ "661:\n\t" \ -- 2.17.1