hfs_get_ushort() and hfs_get_uint() deal with big-endian data, so simply casting to a native type won't work on little-endian machines. Rewrite those macros as inline functions so that their arguments are checked.
Don't dereference type-punned pointers. gcc 4.4 warns about it. ---
fs/hfs_mdb.h | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/fs/hfs_mdb.h b/fs/hfs_mdb.h index 3df549a..169b999 100644 --- a/fs/hfs_mdb.h +++ b/fs/hfs_mdb.h @@ -19,8 +19,15 @@ typedef unsigned char hfs_char_t; typedef unsigned char hfs_ushort_t[2]; typedef unsigned char hfs_uint_t[4];
-#define hfs_get_ushort(addr) (*((unsigned short*)(addr))) -#define hfs_get_uint(addr) (*((unsigned int*)(addr))) +static inline unsigned short hfs_get_ushort(hfs_ushort_t addr) +{ + return (addr[0] << 8) | addr[1]; +} + +static inline unsigned short hfs_get_uint(hfs_uint_t addr) +{ + return (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]; +}
/* * The HFS Master Directory Block (MDB).