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> v2: - Use a more terse approach to round up size suggested by Daniel - Added comment to explain why to have the size rounded --- grub-core/io/bufio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index 22438277d..75adaa135 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -61,6 +61,11 @@ 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 to which the binary math to calculate next_buf + in grub_bufio_read requires. */ + while (size & (size - 1)) + size = (size | (size - 1)) + 1; + 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