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:
Richard Frith-MacDonald 2010-06-25 11:53:21 +00:00
parent ae394881bf
commit 9b72ce7cd0
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>
* Source/NSLocale.m

View file

@ -632,6 +632,13 @@ static NSDictionary *makeReference(unsigned ref)
[_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
{
CHECKKEY

View file

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