All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: grub-devel@gnu.org
Subject: [PATCH] btrfs: avoid "used uninitialized" error with GCC7
Date: Fri, 31 Mar 2017 19:42:06 +0300	[thread overview]
Message-ID: <1490978526-13303-1-git-send-email-arvidjaar@gmail.com> (raw)

sblock was local and so considered new variable on every loop
iteration.

While on it, dynamically allocate buffer to reduce stack usage.

Closes: 50597

---
 grub-core/fs/btrfs.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 9cffa91..99e81f9 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -229,24 +229,29 @@ read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb)
 {
   unsigned i;
   grub_err_t err = GRUB_ERR_NONE;
+  struct grub_btrfs_superblock *sblock;
+
+  sblock = grub_malloc (sizeof (*sblock));
+  if (sblock == NULL)
+    return grub_errno;
+
   for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++)
     {
-      struct grub_btrfs_superblock sblock;
       /* Don't try additional superblocks beyond device size.  */
-      if (i && (grub_le_to_cpu64 (sblock.this_device.size)
+      if (i && (grub_le_to_cpu64 (sblock->this_device.size)
 		>> GRUB_DISK_SECTOR_BITS) <= superblock_sectors[i])
 	break;
       err = grub_disk_read (disk, superblock_sectors[i], 0,
-			    sizeof (sblock), &sblock);
+			    sizeof (*sblock), sblock);
       if (err == GRUB_ERR_OUT_OF_RANGE)
 	break;
 
-      if (grub_memcmp ((char *) sblock.signature, GRUB_BTRFS_SIGNATURE,
+      if (grub_memcmp ((char *) sblock->signature, GRUB_BTRFS_SIGNATURE,
 		       sizeof (GRUB_BTRFS_SIGNATURE) - 1) != 0)
 	break;
-      if (i == 0 || grub_le_to_cpu64 (sblock.generation)
+      if (i == 0 || grub_le_to_cpu64 (sblock->generation)
 	  > grub_le_to_cpu64 (sb->generation))
-	grub_memcpy (sb, &sblock, sizeof (sblock));
+	grub_memcpy (sb, sblock, sizeof (*sblock));
     }
 
   if ((err == GRUB_ERR_OUT_OF_RANGE || !err) && i == 0)
@@ -255,6 +260,7 @@ read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb)
   if (err == GRUB_ERR_OUT_OF_RANGE)
     grub_errno = err = GRUB_ERR_NONE;
 
+  grub_free (sblock);
   return err;
 }
 
-- 
tg: (8014b7b..) bug/50597 (depends on: master)


             reply	other threads:[~2017-03-31 16:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31 16:42 Andrei Borzenkov [this message]
2017-04-03  8:59 ` [PATCH] btrfs: avoid "used uninitialized" error with GCC7 Vladimir 'phcoder' Serbinenko
2017-04-04 16:27   ` Andrei Borzenkov

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=1490978526-13303-1-git-send-email-arvidjaar@gmail.com \
    --to=arvidjaar@gmail.com \
    --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.