From 50157cc4d21403d07658d5a3a2c694b6a95565d1 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sat, 20 Aug 2011 21:20:33 +0000 Subject: [PATCH] [VFATLIB] Fix completely non-standard, broken and retarded definition of GET_UNALIGNED_W for 64 bit architectures The function is supposed to read an unaligned little endian USHORT value. The old version copied the 2 bytes with memcpy to an aligned stack variable and then (bug bug) read the unaligned value directly (discarding the result of the previous operation) and passed it to bswap if neccessary. The new function simply reads the 2 bytes and combines them using << and |. svn path=/trunk/; revision=53348 --- reactos/lib/fslib/vfatlib/check/boot.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/reactos/lib/fslib/vfatlib/check/boot.c b/reactos/lib/fslib/vfatlib/check/boot.c index 302fa050aad..f0c0d6093b2 100644 --- a/reactos/lib/fslib/vfatlib/check/boot.c +++ b/reactos/lib/fslib/vfatlib/check/boot.c @@ -30,19 +30,18 @@ static struct { { 0xff, "5.25\" 320k floppy 2s/40tr/8sec" }, }; -#if defined __alpha || defined __ia64__ || defined __s390x__ || defined __x86_64__ || defined __ppc64__ -/* Unaligned fields must first be copied byte-wise */ -#define GET_UNALIGNED_W(f) \ - ({ \ - unsigned short __v; \ - memcpy( &__v, &f, sizeof(__v) ); \ - CF_LE_W( *(unsigned short *)&f ); \ - }) +#if defined __alpha || defined __ia64__ || defined __x86_64__ || defined __ppc64__ +/* Unaligned fields must first be copied byte-wise (little endian) */ +#define GET_UNALIGNED_W(u) \ + (((unsigned char*)(&u))[0] | (((unsigned char*)&(u))[1] << 8)) +#elif defined __s390x__ +/* Unaligned fields must first be copied byte-wise (big endian) */ +#define GET_UNALIGNED_W(pu) \ + (((unsigned char*)&(u))[1] | (((unsigned char*)&(u))[0] << 8)) #else #define GET_UNALIGNED_W(f) CF_LE_W( *(unsigned short *)&f ) #endif - static char *get_media_descr( unsigned char media ) { int i;