grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/4] Fix ALIGN_UP cutting upper bits


From: Pavel Roskin
Subject: [PATCH 4/4] Fix ALIGN_UP cutting upper bits
Date: Tue, 21 Jul 2009 23:16:59 -0400
User-agent: StGit/0.15-rc1-9-gd8846

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)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]