Rounding up the bufio->block_size to meet power of 2 to facilitate next_buf
calcuation in grub_bufio_read.

Signed-off-by: Michael Chang <mch...@suse.com>
---
 grub-core/io/bufio.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c
index 22438277d..4d66b65a3 100644
--- a/grub-core/io/bufio.c
+++ b/grub-core/io/bufio.c
@@ -61,6 +61,14 @@ grub_bufio_open (grub_file_t io, int size)
     size = ((io->size > GRUB_BUFIO_MAX_SIZE) ? GRUB_BUFIO_MAX_SIZE :
             io->size);
 
+  /* round up size to power of 2 */
+  if (size & (size - 1))
+    {
+      int round_up;
+      for (round_up = 1; round_up < size; round_up <<= 1);
+      size = round_up;
+    }
+
   bufio = grub_zalloc (sizeof (struct grub_bufio) + size);
   if (! bufio)
     {
-- 
2.13.6


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

Reply via email to