If align is unsigned int, ~(align - 1) will also be unsigned int and
will cut addr to 32 bits.  Cast align to the type of addr.  This also
avoid 64-bit calculations if addr is 32-bit.

ChangeLog:

        * include/grub/misc.h (ALIGN_UP): Cast align to the type of addr
        to avoid loss of upper bits if align is unsigned and shorter
        than addr.
---
 include/grub/misc.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/include/grub/misc.h b/include/grub/misc.h
index e229062..769ec5c 100644
--- a/include/grub/misc.h
+++ b/include/grub/misc.h
@@ -25,7 +25,8 @@
 #include <grub/symbol.h>
 #include <grub/err.h>
 
-#define ALIGN_UP(addr, align) (((grub_uint64_t)addr + align - 1) & ~(align - 
1))
+#define ALIGN_UP(addr, align) \
+       ((addr + (typeof (addr)) align - 1) & ~((typeof (addr)) align - 1))
 #define ARRAY_SIZE(array) (sizeof (array) / sizeof (array[0]))
 
 #define grub_dprintf(condition, fmt, args...) grub_real_dprintf(__FILE__, 
__LINE__, condition, fmt, ## args)


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to