Add change checking and NSInteger methods

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30852 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-06-25 11:53:21 +00:00
parent ec4c5cbf64
commit 9f2c523921
3 changed files with 44 additions and 34 deletions

View file

@ -1,3 +1,9 @@
2010-06-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSKeyedArchiver.m:
* Source/NSKeyedUnarchiver.m:
Implement NSInteger methods and add range checking when decoding.
2010-06-25 Richard Frith-Macdonald <rfm@gnu.org> 2010-06-25 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSLocale.m * Source/NSLocale.m

View file

@ -632,6 +632,13 @@ static NSDictionary *makeReference(unsigned ref)
[_enc setObject: [NSNumber numberWithInt: anInteger] forKey: aKey]; [_enc setObject: [NSNumber numberWithInt: anInteger] forKey: aKey];
} }
- (void) encodeInteger: (NSInteger)anInteger forKey: (NSString*)aKey
{
CHECKKEY
[_enc setObject: [NSNumber numberWithInteger: anInteger] forKey: aKey];
}
- (void) encodeInt32: (int32_t)anInteger forKey: (NSString*)aKey - (void) encodeInt32: (int32_t)anInteger forKey: (NSString*)aKey
{ {
CHECKKEY CHECKKEY

View file

@ -492,48 +492,45 @@ static NSMapTable *globalClassMap = 0;
- (int) decodeIntForKey: (NSString*)aKey - (int) decodeIntForKey: (NSString*)aKey
{ {
NSString *oldKey = aKey; int64_t i = [self decodeInt64ForKey: aKey];
GETVAL
if (o != nil)
{
if ([o isKindOfClass: [NSNumber class]] == YES)
{
long long l = [o longLongValue];
return l; #if (INT_MAX < INT64_MAX)
} if (i > INT_MAX || i < INT_MIN)
else {
{ [NSException raise: NSRangeException
[NSException raise: NSInvalidUnarchiveOperationException format: @"[%@ +%@]: value for key(%@) is out of range",
format: @"[%@ +%@]: value for key(%@) is '%@'", NSStringFromClass([self class]), NSStringFromSelector(_cmd), aKey];
NSStringFromClass([self class]), NSStringFromSelector(_cmd),
oldKey, o];
}
} }
return 0; #endif
return (int)i;
}
- (int) decodeIntegerForKey: (NSString*)aKey
{
int64_t i = [self decodeInt64ForKey: aKey];
#if (INTPTR_MAX < INT64_MAX)
if (i > INTPTR_MAX || i < INTPTR_MIN)
{
[NSException raise: NSRangeException
format: @"[%@ +%@]: value for key(%@) is out of range",
NSStringFromClass([self class]), NSStringFromSelector(_cmd), aKey];
}
#endif
return (NSInteger)i;
} }
- (int32_t) decodeInt32ForKey: (NSString*)aKey - (int32_t) decodeInt32ForKey: (NSString*)aKey
{ {
NSString *oldKey = aKey; int64_t i = [self decodeInt64ForKey: aKey];
GETVAL
if (o != nil)
{
if ([o isKindOfClass: [NSNumber class]] == YES)
{
long long l = [o longLongValue];
return l; if (i > INT32_MAX || i < INT32_MIN)
} {
else [NSException raise: NSRangeException
{ format: @"[%@ +%@]: value for key(%@) is out of range",
[NSException raise: NSInvalidUnarchiveOperationException NSStringFromClass([self class]), NSStringFromSelector(_cmd), aKey];
format: @"[%@ +%@]: value for key(%@) is '%@'",
NSStringFromClass([self class]), NSStringFromSelector(_cmd),
oldKey, o];
}
} }
return 0; return (int32_t)i;
} }
- (int64_t) decodeInt64ForKey: (NSString*)aKey - (int64_t) decodeInt64ForKey: (NSString*)aKey