99 lines
4.0 KiB
Diff
99 lines
4.0 KiB
Diff
From 76bf966849534a832c30cd89dbbb8a32939dcbed Mon Sep 17 00:00:00 2001
|
|
From: "Brian C. Lane" <bcl@redhat.com>
|
|
Date: Fri, 13 Nov 2020 15:12:06 -0800
|
|
Subject: [PATCH 37/42] hfs/reloc: Fix gcc 10 warnings about cast alignment
|
|
|
|
---
|
|
libparted/fs/r/hfs/reloc.c | 35 ++++++++++++++++++++---------------
|
|
1 file changed, 20 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/libparted/fs/r/hfs/reloc.c b/libparted/fs/r/hfs/reloc.c
|
|
index d0477ae..68b14ae 100644
|
|
--- a/libparted/fs/r/hfs/reloc.c
|
|
+++ b/libparted/fs/r/hfs/reloc.c
|
|
@@ -373,6 +373,7 @@ hfs_cache_from_catalog(HfsCPrivateCache* cache, PedFileSystem* fs,
|
|
HfsExtDescriptor* extent;
|
|
unsigned int leaf_node, record_number;
|
|
unsigned int i, j;
|
|
+ uint16_t catalog_pos;
|
|
|
|
if (!priv_data->catalog_file->sect_nb) {
|
|
ped_exception_throw (
|
|
@@ -385,8 +386,9 @@ hfs_cache_from_catalog(HfsCPrivateCache* cache, PedFileSystem* fs,
|
|
|
|
if (!hfs_file_read_sector (priv_data->catalog_file, node, 0))
|
|
return 0;
|
|
- header = (HfsHeaderRecord*)(node + PED_BE16_TO_CPU(*((uint16_t*)
|
|
- (node+(PED_SECTOR_SIZE_DEFAULT-2)))));
|
|
+ uint16_t offset;
|
|
+ memcpy(&offset, node+(PED_SECTOR_SIZE_DEFAULT-2), sizeof(uint16_t));
|
|
+ header = (HfsHeaderRecord*) (node + PED_BE16_TO_CPU(offset));
|
|
|
|
for (leaf_node = PED_BE32_TO_CPU (header->first_leaf_node);
|
|
leaf_node;
|
|
@@ -397,14 +399,15 @@ hfs_cache_from_catalog(HfsCPrivateCache* cache, PedFileSystem* fs,
|
|
record_number = PED_BE16_TO_CPU (desc->rec_nb);
|
|
for (i = 1; i <= record_number; ++i) {
|
|
/* undocumented alignement */
|
|
+ uint16_t value;
|
|
+ memcpy(&value, node+(PED_SECTOR_SIZE_DEFAULT - (2*i)), sizeof(uint16_t));
|
|
+ catalog_pos = PED_BE16_TO_CPU(value);
|
|
+ catalog_key = (HfsCatalogKey*) (node + catalog_pos);
|
|
unsigned int skip;
|
|
- catalog_key = (HfsCatalogKey*) (node + PED_BE16_TO_CPU(
|
|
- *((uint16_t*)(node+(PED_SECTOR_SIZE_DEFAULT - 2*i)))));
|
|
skip = (1 + catalog_key->key_length + 1) & ~1;
|
|
- catalog_data = (HfsCatalog*)( ((uint8_t*)catalog_key)
|
|
- + skip );
|
|
+ catalog_data = (HfsCatalog*)(node+catalog_pos+skip);
|
|
/* check for obvious error in FS */
|
|
- if (((uint8_t*)catalog_key - node < HFS_FIRST_REC)
|
|
+ if ((catalog_pos < HFS_FIRST_REC)
|
|
|| ((uint8_t*)catalog_data - node
|
|
>= PED_SECTOR_SIZE_DEFAULT
|
|
- 2 * (signed)(record_number+1))) {
|
|
@@ -467,6 +470,7 @@ hfs_cache_from_extent(HfsCPrivateCache* cache, PedFileSystem* fs,
|
|
HfsExtDescriptor* extent;
|
|
unsigned int leaf_node, record_number;
|
|
unsigned int i, j;
|
|
+ uint16_t extent_pos;
|
|
|
|
if (!priv_data->extent_file->sect_nb) {
|
|
ped_exception_throw (
|
|
@@ -479,8 +483,9 @@ hfs_cache_from_extent(HfsCPrivateCache* cache, PedFileSystem* fs,
|
|
|
|
if (!hfs_file_read_sector (priv_data->extent_file, node, 0))
|
|
return 0;
|
|
- header = ((HfsHeaderRecord*) (node + PED_BE16_TO_CPU(*((uint16_t *)
|
|
- (node+(PED_SECTOR_SIZE_DEFAULT-2))))));
|
|
+ uint16_t offset;
|
|
+ memcpy(&offset, node+(PED_SECTOR_SIZE_DEFAULT-2), sizeof(uint16_t));
|
|
+ header = (HfsHeaderRecord*) (node + PED_BE16_TO_CPU(offset));
|
|
|
|
for (leaf_node = PED_BE32_TO_CPU (header->first_leaf_node);
|
|
leaf_node;
|
|
@@ -491,14 +496,14 @@ hfs_cache_from_extent(HfsCPrivateCache* cache, PedFileSystem* fs,
|
|
record_number = PED_BE16_TO_CPU (desc->rec_nb);
|
|
for (i = 1; i <= record_number; i++) {
|
|
uint8_t where;
|
|
- extent_key = (HfsExtentKey*)
|
|
- (node + PED_BE16_TO_CPU(*((uint16_t *)
|
|
- (node+(PED_SECTOR_SIZE_DEFAULT - 2*i)))));
|
|
+ uint16_t value;
|
|
+ memcpy(&value, node+(PED_SECTOR_SIZE_DEFAULT - (2*i)), sizeof(uint16_t));
|
|
+ extent_pos = PED_BE16_TO_CPU(value);
|
|
+ extent_key = (HfsExtentKey*)(node + extent_pos);
|
|
/* size is cst */
|
|
- extent = (HfsExtDescriptor*)(((uint8_t*)extent_key)
|
|
- + sizeof (HfsExtentKey));
|
|
+ extent = (HfsExtDescriptor*)(node+extent_pos+sizeof(HfsExtentKey));
|
|
/* check for obvious error in FS */
|
|
- if (((uint8_t*)extent_key - node < HFS_FIRST_REC)
|
|
+ if ((extent_pos < HFS_FIRST_REC)
|
|
|| ((uint8_t*)extent - node
|
|
>= PED_SECTOR_SIZE_DEFAULT
|
|
- 2 * (signed)(record_number+1))) {
|
|
--
|
|
2.26.2
|
|
|