Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -233,11 +233,11 @@ { id *objects = [_array items], *copy; size_t count = [_array count]; if (range.length > SIZE_MAX - range.location || - range.length > count - range.location) + range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; copy = [self allocMemoryWithSize: sizeof(*copy) count: range.length]; memcpy(copy, objects + range.location, range.length * sizeof(id)); Index: tests/OFArrayTests.m ================================================================== --- tests/OFArrayTests.m +++ tests/OFArrayTests.m @@ -31,10 +31,114 @@ static OFString *c_ary[] = { @"Foo", @"Bar", @"Baz" }; + +@interface SimpleArray: OFArray +{ + OFMutableArray *_array; +} +@end + +@interface SimpleMutableArray: OFMutableArray +{ + OFMutableArray *_array; +} +@end + +@implementation SimpleArray +- init +{ + self = [super init]; + + @try { + _array = [[OFMutableArray alloc] init]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithObject: (id)object + arguments: (va_list)arguments +{ + self = [super init]; + + @try { + _array = [[OFMutableArray alloc] initWithObject: object + arguments: arguments]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- initWithObjects: (id const*)objects + count: (size_t)count +{ + self = [super init]; + + @try { + _array = [[OFMutableArray alloc] initWithObjects: objects + count: count]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_array release]; + + [super dealloc]; +} + +- (id)objectAtIndex: (size_t)index +{ + return [_array objectAtIndex: index]; +} + +- (size_t)count +{ + return [_array count]; +} +@end + +@implementation SimpleMutableArray ++ (void)initialize +{ + if (self == [SimpleMutableArray class]) + [self inheritMethodsFromClass: [SimpleArray class]]; +} + +- (void)insertObject: (id)object + atIndex: (size_t)index +{ + [_array insertObject: object + atIndex: index]; +} + +- (void)replaceObjectAtIndex: (size_t)index + withObject: (id)object +{ + [_array replaceObjectAtIndex: index + withObject: object]; +} + +- (void)removeObjectAtIndex: (size_t)index +{ + [_array removeObjectAtIndex: index]; +} +@end @implementation TestsAppDelegate (OFArrayTests) - (void)arrayTestsWithClass: (Class)arrayClass mutableClass: (Class)mutableArrayClass { @@ -44,12 +148,10 @@ OFEnumerator *enumerator; id obj; bool ok; size_t i; - module = [arrayClass className]; - TEST(@"+[array]", (m[0] = [mutableArrayClass array])) TEST(@"+[arrayWithObjects:]", (a[0] = [arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil])) @@ -349,9 +451,14 @@ [pool drain]; } - (void)arrayTests { + module = @"OFArray"; + [self arrayTestsWithClass: [SimpleArray class] + mutableClass: [SimpleMutableArray class]]; + + module = @"OFArray_adjacent"; [self arrayTestsWithClass: [OFArray class] mutableClass: [OFMutableArray class]]; } @end