All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Chang <mchang@suse.com>
To: grub-devel@gnu.org
Subject: [PATCH 1/8] cpio: fix gcc9 error address-of-packed-member
Date: Tue,  9 Apr 2019 18:46:52 +0800	[thread overview]
Message-ID: <20190409104659.4125-2-mchang@suse.com> (raw)
In-Reply-To: <20190409104659.4125-1-mchang@suse.com>

Change the read_number function to use void* type as its first argument
to silence the warning. The pointer is later type casted to
grub_uint16_t* and use grub_get_unaligned16 for safely deferencing it
for the value.

The solved gcc9 error like this.

[   59s] In file included from ../grub-core/fs/cpio.c:51:
[   59s] ../grub-core/fs/cpio_common.c: In function 'grub_cpio_find_file':
[   59s] ../grub-core/fs/cpio_common.c:58:31: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    58 |   data->size = read_number (hd.filesize, ARRAY_SIZE (hd.filesize));
[   59s]       |                             ~~^~~~~~~~~
[   59s] ../grub-core/fs/cpio_common.c:60:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    60 |     *mtime = read_number (hd.mtime, ARRAY_SIZE (hd.mtime));
[   59s]       |                           ~~^~~~~~
[   59s] ../grub-core/fs/cpio_common.c:61:28: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    61 |   modeval = read_number (hd.mode, ARRAY_SIZE (hd.mode));
[   59s]       |                          ~~^~~~~
[   59s] ../grub-core/fs/cpio_common.c:62:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    62 |   namesize = read_number (hd.namesize, ARRAY_SIZE (hd.namesize));
[   59s]       |                           ~~^~~~~~~~~
[   59s] In file included from ../grub-core/fs/cpio_be.c:51:
[   59s] ../grub-core/fs/cpio_common.c: In function 'grub_cpio_find_file':
[   59s] ../grub-core/fs/cpio_common.c:58:31: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    58 |   data->size = read_number (hd.filesize, ARRAY_SIZE (hd.filesize));
[   59s]       |                             ~~^~~~~~~~~
[   59s] ../grub-core/fs/cpio_common.c:60:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    60 |     *mtime = read_number (hd.mtime, ARRAY_SIZE (hd.mtime));
[   59s]       |                           ~~^~~~~~
[   59s] ../grub-core/fs/cpio_common.c:61:28: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    61 |   modeval = read_number (hd.mode, ARRAY_SIZE (hd.mode));
[   59s]       |                          ~~^~~~~
[   59s] ../grub-core/fs/cpio_common.c:62:29: error: taking address of packed member of 'struct head' may result in an unaligned pointer value [-Werror=address-of-packed-member]
[   59s]    62 |   namesize = read_number (hd.namesize, ARRAY_SIZE (hd.namesize));
[   59s]       |                           ~~^~~~~~~~~

Signed-off-by: Michael Chang <mchang@suse.com>
---
 grub-core/fs/cpio.c    | 5 +++--
 grub-core/fs/cpio_be.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/grub-core/fs/cpio.c b/grub-core/fs/cpio.c
index dab5f9898..a1aa66689 100644
--- a/grub-core/fs/cpio.c
+++ b/grub-core/fs/cpio.c
@@ -38,11 +38,12 @@ struct head
 } GRUB_PACKED;
 
 static inline unsigned long long
-read_number (const grub_uint16_t *arr, grub_size_t size)
+read_number (const void *arr, grub_size_t size)
 {
   long long ret = 0;
+  const grub_uint16_t *p = (const grub_uint16_t *)arr;
   while (size--)
-    ret = (ret << 16) | grub_le_to_cpu16 (*arr++);
+    ret = (ret << 16) | grub_le_to_cpu16 (grub_get_unaligned16 (p++));
   return ret;
 }
 
diff --git a/grub-core/fs/cpio_be.c b/grub-core/fs/cpio_be.c
index 846548892..9460d0ec1 100644
--- a/grub-core/fs/cpio_be.c
+++ b/grub-core/fs/cpio_be.c
@@ -38,11 +38,12 @@ struct head
 } GRUB_PACKED;
 
 static inline unsigned long long
-read_number (const grub_uint16_t *arr, grub_size_t size)
+read_number (const void *arr, grub_size_t size)
 {
   long long ret = 0;
+  const grub_uint16_t *p = (const grub_uint16_t *)arr;
   while (size--)
-    ret = (ret << 16) | grub_be_to_cpu16 (*arr++);
+    ret = (ret << 16) | grub_be_to_cpu16 (grub_get_unaligned16 (p++));
   return ret;
 }
 
-- 
2.16.4



  reply	other threads:[~2019-04-09 10:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-09 10:46 [PATCH 0/8] fix gcc9 build with -Werror=address-of-packed-member Michael Chang
2019-04-09 10:46 ` Michael Chang [this message]
2019-04-09 10:46 ` [PATCH 2/8] jfs: fix gcc9 error address-of-packed-member Michael Chang
2019-04-09 10:46 ` [PATCH 3/8] hfs: " Michael Chang
2019-04-09 10:46 ` [PATCH 4/8] hfsplus: " Michael Chang
2019-04-09 10:46 ` [PATCH 5/8] acpi: " Michael Chang
2019-04-09 10:46 ` [PATCH 6/8] usbtest: " Michael Chang
2019-04-09 10:46 ` [PATCH 7/8] chainloader: " Michael Chang
2019-04-09 10:46 ` [PATCH 8/8] efi: " Michael Chang
2019-04-09 10:57 ` [PATCH 0/8] fix gcc9 build with -Werror=address-of-packed-member Vladimir 'phcoder' Serbinenko
2019-04-09 11:39   ` Michael Chang
2019-04-09 12:15     ` Vladimir 'phcoder' Serbinenko
2019-04-10  4:41       ` Michael Chang

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=20190409104659.4125-2-mchang@suse.com \
    --to=mchang@suse.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.