diff --git a/ChangeLog b/ChangeLog index 30bab081b..c2b9b843a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-07-17 Richard Frith-Macdonald + + * Source/Additions/GSCategories.m: littleEndian() fix to work on + systems with other word sizes. + 2008-07-05 Richard Frith-Macdonald * Version 1.16.3 diff --git a/Source/Additions/GSCategories.m b/Source/Additions/GSCategories.m index c7099e98e..01320dec3 100644 --- a/Source/Additions/GSCategories.m +++ b/Source/Additions/GSCategories.m @@ -392,23 +392,27 @@ static void MD5Transform (uint32_t buf[4], uint32_t const in[16]); */ static void littleEndian (void *buf, unsigned words) { - uint32_t *ptr = (uint32_t*)buf; + if (NSHostByteOrder() == NS_BigEndian) + { + while (words-- > 0) + { + union swap { + uint32_t num; + uint8_t byt[4]; + } tmp; + uint8_t b0; + uint8_t b1; -#if (INT_MAX == 2147483647) - do - { - *ptr = NSSwapHostIntToLittle(*ptr); - ptr++; + tmp.num = ((uint32_t*)buf)[words]; + b0 = tmp.byt[0]; + b1 = tmp.byt[1]; + tmp.byt[0] = tmp.byt[3]; + tmp.byt[1] = tmp.byt[2]; + tmp.byt[2] = b1; + tmp.byt[3] = b0; + ((uint32_t*)buf)[words] = tmp.num; + } } - while (--words); -#else - do - { - *ptr = NSSwapHostLongToLittle(*ptr); - ptr++; - } - while (--words); -#endif } /*