diff mbox series

[RFC,09/18] xen: cppcheck: misra rule 20.7 deviation on kconfig.h

Message ID 20221220085100.22848-10-luca.fancellu@arm.com (mailing list archive)
State Superseded
Headers show
Series cppcheck rule 20.7 fixes | expand

Commit Message

Luca Fancellu Dec. 20, 2022, 8:50 a.m. UTC
Cppcheck has found a violation of rule 20.7 for the macro
__config_enabled but the preprocessor branch where this macro is
defined should not be analysed by cppcheck when CPPCHECK macro is
defined, hence this is a false positive of the tool and we can
safely suppress the finding.

Eclair and coverity does not report this finding.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
 docs/misra/false-positive-cppcheck.json | 7 +++++++
 xen/include/xen/kconfig.h               | 1 +
 2 files changed, 8 insertions(+)

Comments

Jan Beulich Dec. 20, 2022, 9:48 a.m. UTC | #1
On 20.12.2022 09:50, Luca Fancellu wrote:
> Cppcheck has found a violation of rule 20.7 for the macro
> __config_enabled but the preprocessor branch where this macro is
> defined should not be analysed by cppcheck when CPPCHECK macro is
> defined, hence this is a false positive of the tool and we can
> safely suppress the finding.

So what was commit 43aa3f6e72d3's ("xen/build: Add cppcheck and
cppcheck-html make rules") adjustment to the file about then?

Jan
Luca Fancellu Dec. 21, 2022, 9:54 a.m. UTC | #2
> On 20 Dec 2022, at 09:48, Jan Beulich <jbeulich@suse.com> wrote:
> 
> On 20.12.2022 09:50, Luca Fancellu wrote:
>> Cppcheck has found a violation of rule 20.7 for the macro
>> __config_enabled but the preprocessor branch where this macro is
>> defined should not be analysed by cppcheck when CPPCHECK macro is
>> defined, hence this is a false positive of the tool and we can
>> safely suppress the finding.
> 
> So what was commit 43aa3f6e72d3's ("xen/build: Add cppcheck and
> cppcheck-html make rules") adjustment to the file about then?

Yes the commit is right, cppcheck itself needs that, the problem here
comes from the misra add-on (the cppcheck component that does the
MISRA analysis) that is wrong.

Anyway I will drop this patch together with all the false-positive on the
Tool for now.

> 
> Jan
>
diff mbox series

Patch

diff --git a/docs/misra/false-positive-cppcheck.json b/docs/misra/false-positive-cppcheck.json
index 5e7d9377f60b..c8ee3c0c6317 100644
--- a/docs/misra/false-positive-cppcheck.json
+++ b/docs/misra/false-positive-cppcheck.json
@@ -17,6 +17,13 @@ 
         },
         {
             "id": "SAF-2-false-positive-cppcheck",
+            "violation-id": "misra-c2012-20.7",
+            "tool-version": "2.7",
+            "name": "R20.7 on preprocessor branch that should be disabled",
+            "text": "This preprocessor branch should be disabled when CPPCHECK macro is active, so there should not be violation."
+        },
+        {
+            "id": "SAF-3-false-positive-cppcheck",
             "violation-id": "",
             "tool-version": "",
             "name": "Sentinel",
diff --git a/xen/include/xen/kconfig.h b/xen/include/xen/kconfig.h
index a717b0819c2e..92373c018950 100644
--- a/xen/include/xen/kconfig.h
+++ b/xen/include/xen/kconfig.h
@@ -23,6 +23,7 @@ 
 #define __ARG_PLACEHOLDER_1 0,
 #define config_enabled(cfg) _config_enabled(cfg)
 #define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
+/* SAF-2-false-positive-cppcheck R20.7 but cppcheck should not check here */
 #define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
 #define ___config_enabled(__ignored, val, ...) val