[PATCH 5/7] xen/rbtree: Fix MISRA C 2012 Rule 20.7 violation

Xenia Ragiadakou posted 7 patches 3 years, 5 months ago
[PATCH 5/7] xen/rbtree: Fix MISRA C 2012 Rule 20.7 violation
Posted by Xenia Ragiadakou 3 years, 5 months ago
In macro __rb_parent(), add parentheses around the macro parameter to prevent
against unintended expansions.

Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>
---
 xen/lib/rbtree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/lib/rbtree.c b/xen/lib/rbtree.c
index 85a4f20313..eb418baabb 100644
--- a/xen/lib/rbtree.c
+++ b/xen/lib/rbtree.c
@@ -46,7 +46,7 @@
 #define		RB_RED		0
 #define		RB_BLACK	1
 
-#define __rb_parent(pc)    ((struct rb_node *)(pc & ~3))
+#define __rb_parent(pc)    ((struct rb_node *)((pc) & ~3))
 
 #define __rb_color(pc)     ((pc) & 1)
 #define __rb_is_black(pc)  __rb_color(pc)
-- 
2.34.1
Re: [PATCH 5/7] xen/rbtree: Fix MISRA C 2012 Rule 20.7 violation
Posted by Stefano Stabellini 3 years, 5 months ago
On Fri, 19 Aug 2022, Xenia Ragiadakou wrote:
> In macro __rb_parent(), add parentheses around the macro parameter to prevent
> against unintended expansions.
> 
> Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
>  xen/lib/rbtree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/lib/rbtree.c b/xen/lib/rbtree.c
> index 85a4f20313..eb418baabb 100644
> --- a/xen/lib/rbtree.c
> +++ b/xen/lib/rbtree.c
> @@ -46,7 +46,7 @@
>  #define		RB_RED		0
>  #define		RB_BLACK	1
>  
> -#define __rb_parent(pc)    ((struct rb_node *)(pc & ~3))
> +#define __rb_parent(pc)    ((struct rb_node *)((pc) & ~3))
>  
>  #define __rb_color(pc)     ((pc) & 1)
>  #define __rb_is_black(pc)  __rb_color(pc)
> -- 
> 2.34.1
>