Skip to contentSkip to conversation

cppcheck rule 20.7 fixes

PATCH New Luca Fancellu 1 participant 3 messages Dec 21, 2022

lore
Share & tools
lore
#0 lore raw

cover cppcheck rule 20.7 fixes

In this serie there are some fixes for the rule 20.7.

The analysed build is arm64, to reproduce the reports here the command:

./xen/scripts/xen-analysis.py --cppcheck-misra --run-cppcheck -- CROSS_COMPILE="aarch64-linux-gnu-" XEN_TARGET_ARCH="arm64" O=/path/to/artifacts_folder

Luca Fancellu (2):
public: misra rule 20.7 fix on errno.h
public: misra rule 20.7 fix on memory.h

 xen/include/public/errno.h  | 2 +-
 xen/include/public/memory.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 public: misra rule 20.7 fix on errno.h

Cppcheck has found a violation of rule 20.7 for the macro XEN_ERRNO, while the macro parameter is never used as an expression, it doesn't harm the code or the readability to add parenthesis, so add them.

This finding is reported also by eclair and coverity.

---
 xen/include/public/errno.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/public/errno.h +1 -1
index 6bdc8c507990..5a78a7607c0d 100644
@@ -31,7 +31,7 @@
 
 #ifndef __ASSEMBLY__
 
-#define XEN_ERRNO(name, value) XEN_##name = value,
+#define XEN_ERRNO(name, value) XEN_##name = (value),
 enum xen_errno {
 
 #elif __XEN_INTERFACE_VERSION__ < 0x00040700
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 public: misra rule 20.7 fix on memory.h

In reply to Luca Fancellu

Cppcheck has found a violation of rule 20.7 for the macro XENMEM_SHARING_OP_FIELD_MAKE_GREF, the argument "val" is used in an expression, hence add parenthesis to the argument "val" to fix the violation.

---
 xen/include/public/memory.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/public/memory.h +1 -1
index 29cf5c823902..c5f0d31e235d 100644
@@ -485,7 +485,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
 #define XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG   (xen_mk_ullong(1) << 62)
 
 #define XENMEM_SHARING_OP_FIELD_MAKE_GREF(field, val)  \
-    (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | val)
+    (field) = (XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG | (val))
 #define XENMEM_SHARING_OP_FIELD_IS_GREF(field)         \
     ((field) & XENMEM_SHARING_OP_FIELD_IS_GREF_FLAG)
 #define XENMEM_SHARING_OP_FIELD_GET_GREF(field)        \
Signature · 1 line
2.17.1