Re: [PATCH v7 02/17] misc: Add parentheses around ALIGN_UP and ALIGN_DOWN arguments
On Fri, Dec 04, 2020 at 10:43:31AM -0600, Glenn Washburn wrote: > This ensures that expected order of operations is preserved when arguments > are expressions. > > Signed-off-by: Glenn Washburn Good catch! Reviewed-by: Daniel Kiper Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH v7 02/17] misc: Add parentheses around ALIGN_UP and ALIGN_DOWN arguments
On Fri, Dec 04, 2020 at 10:43:31AM -0600, Glenn Washburn wrote: > This ensures that expected order of operations is preserved when arguments > are expressions. > > Signed-off-by: Glenn Washburn Reviewed-by: Patrick Steinhardt > --- > include/grub/misc.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/grub/misc.h b/include/grub/misc.h > index b7ca6dd58..780a34e90 100644 > --- a/include/grub/misc.h > +++ b/include/grub/misc.h > @@ -28,10 +28,10 @@ > #include > > #define ALIGN_UP(addr, align) \ > - ((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1)) > + (((addr) + (typeof (addr)) (align) - 1) & ~((typeof (addr)) (align) - > 1)) > #define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) > - 1)) > #define ALIGN_DOWN(addr, align) \ > - ((addr) & ~((typeof (addr)) align - 1)) > + ((addr) & ~((typeof (addr)) (align) - 1)) > #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) > #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } > > -- > 2.27.0 > signature.asc Description: PGP signature ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH v7 02/17] misc: Add parentheses around ALIGN_UP and ALIGN_DOWN arguments
This ensures that expected order of operations is preserved when arguments are expressions. Signed-off-by: Glenn Washburn --- include/grub/misc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grub/misc.h b/include/grub/misc.h index b7ca6dd58..780a34e90 100644 --- a/include/grub/misc.h +++ b/include/grub/misc.h @@ -28,10 +28,10 @@ #include #define ALIGN_UP(addr, align) \ - ((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1)) + (((addr) + (typeof (addr)) (align) - 1) & ~((typeof (addr)) (align) - 1)) #define ALIGN_UP_OVERHEAD(addr, align) ((-(addr)) & ((typeof (addr)) (align) - 1)) #define ALIGN_DOWN(addr, align) \ - ((addr) & ~((typeof (addr)) align - 1)) + ((addr) & ~((typeof (addr)) (align) - 1)) #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0])) #define COMPILE_TIME_ASSERT(cond) switch (0) { case 1: case !(cond): ; } -- 2.27.0 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel