bugfix for byte swapping

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37196 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2013-10-04 08:07:10 +00:00
parent 8276ff4171
commit d86cd7382b
2 changed files with 7 additions and 25 deletions

View file

@ -1,3 +1,7 @@
2013-10-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSTimeZone.m: Fix bug with byte swapping ... use NSByteOrder.h
2013-10-01 Richard Frith-Macdonald <rfm@gnu.org> 2013-10-01 Richard Frith-Macdonald <rfm@gnu.org>
* config/config.align.c: Try to more reliably detect whether word * config/config.align.c: Try to more reliably detect whether word

View file

@ -296,30 +296,6 @@ static NSRecursiveLock *zone_mutex = nil;
static Class NSTimeZoneClass; static Class NSTimeZoneClass;
static Class GSPlaceholderTimeZoneClass; static Class GSPlaceholderTimeZoneClass;
/* Decode the four bytes at PTR as a signed integer in network byte order.
Based on code included in the GNU C Library 2.0.3. */
static inline int
decode (const void *ptr)
{
#if defined(WORDS_BIGENDIAN) && SIZEOF_INT == 4
#if NEED_WORD_ALIGNMENT
int value;
memcpy(&value, ptr, sizeof(NSInteger));
return value;
#else
return *(const NSInteger*) ptr;
#endif
#else /* defined(WORDS_BIGENDIAN) && SIZEOF_INT == 4 */
const unsigned char *p = ptr;
int result = *p & (1 << (CHAR_BIT - 1)) ? ~0 : 0;
result = (result << 8) | *p++;
result = (result << 8) | *p++;
result = (result << 8) | *p++;
result = (result << 8) | *p;
return result;
#endif /* defined(WORDS_BIGENDIAN) && SIZEOF_INT == 4 */
}
/* Return path to a TimeZone directory file */ /* Return path to a TimeZone directory file */
static NSString *_time_zone_path(NSString *subpath, NSString *type) static NSString *_time_zone_path(NSString *subpath, NSString *type)
@ -3113,10 +3089,12 @@ newDetailInZoneForType(GSTimeZone *zone, TypeInfo *type)
for (i = 0; i < n_types; i++) for (i = 0; i < n_types; i++)
{ {
struct ttinfo *ptr = (struct ttinfo*)(bytes + pos); struct ttinfo *ptr = (struct ttinfo*)(bytes + pos);
uint32_t off;
types[i].isdst = (ptr->isdst != 0 ? YES : NO); types[i].isdst = (ptr->isdst != 0 ? YES : NO);
types[i].abbr_idx = ptr->abbr_idx; types[i].abbr_idx = ptr->abbr_idx;
types[i].offset = decode(ptr->offset); memcpy(&off, ptr->offset, 4);
types[i].offset = GSSwapBigI32ToHost(off);
pos += sizeof(struct ttinfo); pos += sizeof(struct ttinfo);
} }
abbr = (unsigned char*)(bytes + pos); abbr = (unsigned char*)(bytes + pos);