]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge):
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 25 Oct 2011 16:20:39 +0000 (18:20 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Tue, 25 Oct 2011 16:20:39 +0000 (18:20 +0200)
Use union to avoid breaking strict-aliasing rules.

ChangeLog
grub-core/loader/i386/bsd.c

index a9b26a3137192875905b1aea5a98b18c7e8142a1..8c8af24e44c1036a67c3697946ced25536a73fbf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-10-25  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/loader/i386/bsd.c (grub_netbsd_add_boot_disk_and_wedge):
+       Use union to avoid breaking strict-aliasing rules.
+
 2011-10-25  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Support multi-extent iso files.
index 18ebeb760be9194ee49afba1d4fd0053dfb84505..f2d0845f89fca1c8f239afdaef04e9ec87ba54d2 100644 (file)
@@ -960,8 +960,10 @@ grub_netbsd_add_boot_disk_and_wedge (void)
   grub_partition_t part;
   grub_uint32_t biosdev;
   grub_uint32_t partmapsector;
-  struct grub_partition_bsd_disk_label *label;
-  grub_uint64_t buf[GRUB_DISK_SECTOR_SIZE / 8];
+  union {
+    grub_uint64_t raw[GRUB_DISK_SECTOR_SIZE / 8];
+    struct grub_partition_bsd_disk_label label;
+  } buf;
   grub_uint8_t *hash;
   grub_uint64_t ctx[(GRUB_MD_MD5->contextsize + 7) / 8];
 
@@ -981,7 +983,8 @@ grub_netbsd_add_boot_disk_and_wedge (void)
   partmapsector = grub_partition_get_start (part->parent) + part->offset;
 
   disk->partition = part->parent;
-  if (grub_disk_read (disk, part->offset, 0, GRUB_DISK_SECTOR_SIZE, buf) != GRUB_ERR_NONE)
+  if (grub_disk_read (disk, part->offset, 0, GRUB_DISK_SECTOR_SIZE, buf.raw)
+      != GRUB_ERR_NONE)
     goto fail;
   disk->partition = part;
 
@@ -997,7 +1000,7 @@ grub_netbsd_add_boot_disk_and_wedge (void)
     biw.matchnblks = 1;
 
     GRUB_MD_MD5->init (&ctx);
-    GRUB_MD_MD5->write (&ctx, buf, GRUB_DISK_SECTOR_SIZE);
+    GRUB_MD_MD5->write (&ctx, buf.raw, GRUB_DISK_SECTOR_SIZE);
     GRUB_MD_MD5->final (&ctx);
     hash = GRUB_MD_MD5->read (&ctx);
     memcpy (biw.matchhash, hash, 16);
@@ -1006,18 +1009,17 @@ grub_netbsd_add_boot_disk_and_wedge (void)
   }
 
   /* Fill bootdisk if this a NetBSD disk label.  */
-  label = (struct grub_partition_bsd_disk_label *) &buf;
   if (part->partmap != NULL &&
       (grub_strcmp (part->partmap->name, "netbsd") == 0) &&
-      label->magic == grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
+      buf.label.magic == grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
     {
       struct grub_netbsd_btinfo_bootdisk bid;
 
       grub_memset (&bid, 0, sizeof (bid));
       bid.labelsector = partmapsector;
-      bid.label.type = label->type;
-      bid.label.checksum = label->checksum;
-      memcpy (bid.label.packname, label->packname, 16);
+      bid.label.type = buf.label.type;
+      bid.label.checksum = buf.label.checksum;
+      memcpy (bid.label.packname, buf.label.packname, 16);
       bid.biosdev = biosdev;
       bid.partition = part->number;
       grub_bsd_add_meta (NETBSD_BTINFO_BOOTDISK, &bid, sizeof (bid));