Little changes to avoid strict alias warning for type punning.

This commit is contained in:
Tilo Prütz 2012-03-06 17:24:41 +01:00
parent 1a86ca8d03
commit ee35ec765c
3 changed files with 40 additions and 53 deletions

View File

@ -209,14 +209,16 @@ static void byteCopy(void *src,void *dst,NSUInteger length){
if (naturalSize == promotedSize) {
byteCopy(_argumentFrame + _argumentOffsets[index], pointerToValue, naturalSize);
} else if (promotedSize == 4) {
uint8_t promoted[promotedSize];
} else if (promotedSize == sizeof(long)) {
long promoted;
byteCopy(_argumentFrame+_argumentOffsets[index],promoted,promotedSize);
byteCopy(_argumentFrame + _argumentOffsets[index], &promoted, promotedSize);
if (naturalSize == 1) {
*((char *)pointerToValue) = *((int *)promoted);
*((char *)pointerToValue) = (char)promoted;
} else if (naturalSize == 2) {
*((short *)pointerToValue) = *((int *)promoted);
*((short *)pointerToValue) = (short)promoted;
} else if (naturalSize == 4) {
*((int32_t *)pointerToValue) = (int32_t)promoted;
}
} else {
[NSException raise:NSInvalidArgumentException format:@"Unable to convert naturalSize=%d to promotedSize=%d", naturalSize, promotedSize];
@ -232,17 +234,17 @@ static void byteCopy(void *src,void *dst,NSUInteger length){
if (naturalSize == promotedSize) {
byteCopy(pointerToValue, _argumentFrame + _argumentOffsets[index], naturalSize);
} else if (promotedSize == sizeof(long)) {
uint8_t promoted[promotedSize];
long promoted;
if (naturalSize == 1) {
*((long *)promoted) = *((char *)pointerToValue);
promoted = *((char *)pointerToValue);
} else if (naturalSize == 2) {
*((long *)promoted) = *((short *)pointerToValue);
promoted = *((short *)pointerToValue);
} else if (naturalSize == 4) {
*((long *)promoted) = *((int *)pointerToValue);
promoted = *((int32_t *)pointerToValue);
}
byteCopy(promoted, _argumentFrame + _argumentOffsets[index], promotedSize);
byteCopy(&promoted, _argumentFrame + _argumentOffsets[index], promotedSize);
} else {
[NSException raise:NSInvalidArgumentException format:@"Unable to convert naturalSize=" NSUIntegerFormat " to promotedSize=" NSUIntegerFormat, naturalSize, promotedSize];
}

View File

@ -90,9 +90,11 @@ static inline double _readFloatOfSize(NSPropertyListReader_binary1 *self, size_t
if (size == 4) {
uint32_t val32 = (uint32_t)val;
return *(float *)&val32;
void *p = &val32;
return *((float *)p);
} else if (size == 8) {
return *(double *)&val;
void *p = &val;
return *((double *)p);
}
[NSException raise: @"Invalid size" format: @"Don't know how to read float of size %u", size];
@ -212,10 +214,12 @@ static id _readObjectAtOffset(NSPropertyListReader_binary1 *self,NSUInteger *off
if (size == 4) {
uint32_t val32 = (uint32_t)val;
return [[NSNumber alloc] initWithFloat: *(float*)&val32];
void *p = &val32;
return [[NSNumber alloc] initWithFloat: *(float*)p];
}
if (size == 8) {
return [[NSNumber alloc] initWithDouble: *(double*)&val];
void *p = &val;
return [[NSNumber alloc] initWithDouble: *(double*)p];
}
return [[NSNumber alloc] initWithDouble:0.0];
}

View File

@ -25,45 +25,26 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSFileManager.h>
#import <Foundation/NSRaiseException.h>
// structures in tzfiles are big-endian, from public domain tzfile.h
#define TZ_MAGIC "TZif"
// structures in tzfiles are big-endian
// for definition of file format see
// http://www.kernel.org/doc/man-pages/online/pages/man5/tzfile.5.html
#define TZ_MAGIC "TZif"
struct tzhead {
char tzh_magic[4]; /* TZ_MAGIC */
char tzh_reserved[16]; /* reserved for future use */
char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
char tzh_leapcnt[4]; /* coded number of leap seconds */
char tzh_timecnt[4]; /* coded number of transition times */
char tzh_typecnt[4]; /* coded number of local time types */
char tzh_charcnt[4]; /* coded number of abbr. chars */
char tzh_magic[4]; /* TZ_MAGIC */
char tzh_version[1]; /* version of the file's format (as of 2005, either an ASCII NUL ('\0')
or a '2') */
char tzh_reserved[15]; /* reserved for future use */
int32_t tzh_ttisgmtcnt; /* coded number of trans. time flags */
int32_t tzh_ttisstdcnt; /* coded number of trans. time flags */
int32_t tzh_leapcnt; /* coded number of leap seconds */
int32_t tzh_timecnt; /* coded number of transition times */
int32_t tzh_typecnt; /* coded number of local time types */
int32_t tzh_charcnt; /* coded number of abbr. chars */
};
/*
** . . .followed by. . .
**
** tzh_timecnt (char [4])s coded transition times a la time(2)
** tzh_timecnt (unsigned char)s types of local time starting at above
** tzh_typecnt repetitions of
** one (char [4]) coded UTC offset in seconds
** one (unsigned char) used to set tm_isdst
** one (unsigned char) that's an abbreviation list index
** tzh_charcnt (char)s '\0'-terminated zone abbreviations
** tzh_leapcnt repetitions of
** one (char [4]) coded leap second transition times
** one (char [4]) total correction after above
** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
** time is standard time, if FALSE,
** transition time is wall clock time
** if absent, transition times are
** assumed to be wall clock time
** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
** time is UTC, if FALSE,
** transition time is local time
** if absent, transition times are
** assumed to be local time
*/
// private classes
#import <Foundation/NSTimeZoneTransition.h>
@ -120,11 +101,11 @@ NSInteger sortTransitions(id trans1, id trans2, void *context) {
tzData = (const char *)tzHeader + sizeof(struct tzhead);
//unused
//numberOfGMTFlags = NSSwapBigIntToHost(*((int *)tzHeader->tzh_ttisgmtcnt));
//numberOfStandardFlags = NSSwapBigIntToHost(*((int *)tzHeader->tzh_ttisstdcnt));
//numberOfAbbreviationCharacters = NSSwapBigIntToHost(*((int *)tzHeader->tzh_charcnt));
numberOfTransitionTimes = NSSwapBigIntToHost(*((int *)tzHeader->tzh_timecnt));
numberOfLocalTimes = NSSwapBigIntToHost(*((int *)tzHeader->tzh_typecnt));
//numberOfGMTFlags = NSSwapBigIntToHost(tzHeader->tzh_ttisgmtcnt);
//numberOfStandardFlags = NSSwapBigIntToHost(tzHeader->tzh_ttisstdcnt);
//numberOfAbbreviationCharacters = NSSwapBigIntToHost(tzHeader->tzh_charcnt);
numberOfTransitionTimes = NSSwapBigIntToHost(tzHeader->tzh_timecnt);
numberOfLocalTimes = NSSwapBigIntToHost(tzHeader->tzh_typecnt);
typeIndices = tzData + (numberOfTransitionTimes * 4);
for (i = 0; i < numberOfTransitionTimes; ++i) {