[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 7/8] chainloader: fix gcc9 error address-of-packed-member
From: |
Michael Chang |
Subject: |
[PATCH 7/8] chainloader: fix gcc9 error address-of-packed-member |
Date: |
Tue, 9 Apr 2019 18:46:58 +0800 |
Copy the packed member fp->path_name to the buffer path_name returned by
grub_malloc, which is supposed to be suitably aligned for any data type
and use path_name as argument to grub_utf8_to_utf16. After the function
grub_utf8_to_utf16 returns, copy the content of path_name back to
fp->path_name.
The solved gcc9 error like this.
[ 243s] ../../grub-core/loader/efi/chainloader.c: In function 'copy_file_path':
[ 243s] ../../grub-core/loader/efi/chainloader.c:136:32: error: taking address
of packed member of 'struct grub_efi_file_path_device_path' may result in an
unaligned pointer value [-Werror=address-of-packed-member]
[ 243s] 136 | size = grub_utf8_to_utf16 (fp->path_name, len *
GRUB_MAX_UTF16_PER_UTF8,
[ 243s] | ~~^~~~~~~~~~~
[ 243s] ../../grub-core/loader/efi/chainloader.c:138:12: error: taking address
of packed member of 'struct grub_efi_file_path_device_path' may result in an
unaligned pointer value [-Werror=address-of-packed-member]
[ 243s] 138 | for (p = fp->path_name; p < fp->path_name + size; p++)
[ 243s] | ^~
Signed-off-by: Michael Chang <address@hidden>
---
grub-core/loader/efi/chainloader.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/grub-core/loader/efi/chainloader.c
b/grub-core/loader/efi/chainloader.c
index f706b1ac3..cd92ea3f2 100644
--- a/grub-core/loader/efi/chainloader.c
+++ b/grub-core/loader/efi/chainloader.c
@@ -110,21 +110,27 @@ static void
copy_file_path (grub_efi_file_path_device_path_t *fp,
const char *str, grub_efi_uint16_t len)
{
- grub_efi_char16_t *p;
+ grub_efi_char16_t *p, *path_name;
grub_efi_uint16_t size;
fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE;
fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE;
- size = grub_utf8_to_utf16 (fp->path_name, len * GRUB_MAX_UTF16_PER_UTF8,
+ path_name = grub_malloc (len * GRUB_MAX_UTF16_PER_UTF8 * sizeof
(*path_name));
+ if (!path_name)
+ return;
+
+ size = grub_utf8_to_utf16 (path_name, len * GRUB_MAX_UTF16_PER_UTF8,
(const grub_uint8_t *) str, len, 0);
- for (p = fp->path_name; p < fp->path_name + size; p++)
+ for (p = path_name; p < path_name + size; p++)
if (*p == '/')
*p = '\\';
+ grub_memcpy (fp->path_name, path_name, size * sizeof (*fp->path_name));
/* File Path is NULL terminated */
fp->path_name[size++] = '\0';
fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp);
+ grub_free (path_name);
}
static grub_efi_device_path_t *
--
2.16.4
- [PATCH 0/8] fix gcc9 build with -Werror=address-of-packed-member, Michael Chang, 2019/04/09
- [PATCH 3/8] hfs: fix gcc9 error address-of-packed-member, Michael Chang, 2019/04/09
- [PATCH 4/8] hfsplus: fix gcc9 error address-of-packed-member, Michael Chang, 2019/04/09
- [PATCH 6/8] usbtest: fix gcc9 error address-of-packed-member, Michael Chang, 2019/04/09
- [PATCH 2/8] jfs: fix gcc9 error address-of-packed-member, Michael Chang, 2019/04/09
- [PATCH 1/8] cpio: fix gcc9 error address-of-packed-member, Michael Chang, 2019/04/09
- [PATCH 7/8] chainloader: fix gcc9 error address-of-packed-member,
Michael Chang <=
- [PATCH 5/8] acpi: fix gcc9 error address-of-packed-member, Michael Chang, 2019/04/09
- [PATCH 8/8] efi: fix gcc9 error address-of-packed-member, Michael Chang, 2019/04/09
- Re: [PATCH 0/8] fix gcc9 build with -Werror=address-of-packed-member, Vladimir 'phcoder' Serbinenko, 2019/04/09