Re: Weird NSUnarchiver "more data than room " exception
Re: Weird NSUnarchiver "more data than room " exception
- Subject: Re: Weird NSUnarchiver "more data than room " exception
- From: Mike Laster <email@hidden>
- Date: Fri, 3 Oct 2003 16:40:15 -0400
In experimenting I tracked it down. It appears to be a bug in
Foundation. It is incapable of encoding the long value of -2147483648.
Decoding it generates the exception I get.
Here is a test program that exhibits the bug:
#import <Foundation/Foundation.h>
@interface TestClass: NSObject <NSCoding>
{
long longValue;
}
@end
@implementation TestClass
- (id) init
{
self = [super init];
if (self != nil)
{
NSLog(@"LONG_MIN is %ld (%#x)", LONG_MIN, LONG_MIN);
NSLog(@"LONG_MAX is %ld (%#x)", LONG_MAX, LONG_MAX);
longValue = -2147483648L;
NSLog(@"logValue initialized to %ld (%#x)", longValue,
longValue);
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeValueOfObjCType:@encode(long) at:&longValue];
return;
}
- (id)initWithCoder:(NSCoder *)coder
{
[coder decodeValueOfObjCType:@encode(long) at:&longValue];
return self;
}
@end
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
TestClass *test = [[TestClass alloc] init];
NSData *archivedData = nil;
TestClass *decoded = nil;
archivedData = [NSArchiver archivedDataWithRootObject:test];
NSLog(@"archived to %@", archivedData);
decoded = [NSUnarchiver unarchiveObjectWith
Data:archivedData];
[test release];
[pool release];
return 0;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.