All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: grub-devel@gnu.org
Subject: [PATCH 4/4] Fix ALIGN_UP cutting upper bits
Date: Tue, 21 Jul 2009 23:16:59 -0400	[thread overview]
Message-ID: <20090722031659.6348.7591.stgit@mj.roinet.com> (raw)
In-Reply-To: <20090722031638.6348.79007.stgit@mj.roinet.com>

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)



      parent reply	other threads:[~2009-07-22  3:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-22  3:16 [PATCH 1/4] Handle errors in rmmod Pavel Roskin
2009-07-22  3:16 ` [PATCH 2/4] Fix insmod not to increase refcount above 1 Pavel Roskin
2009-07-22  3:16 ` [PATCH 3/4] Change grub_file_seek() to return grub_err_t Pavel Roskin
2009-07-23  8:23   ` Vladimir 'phcoder' Serbinenko
2009-07-23 19:14     ` Pavel Roskin
2009-07-22  3:16 ` Pavel Roskin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090722031659.6348.7591.stgit@mj.roinet.com \
    --to=proski@gnu.org \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.