Fix bug in returning array from completePathIntoString ...

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3246 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1998-11-19 20:42:06 +00:00
parent 741b9677b0
commit e2fb9ad2aa

View file

@ -754,8 +754,11 @@ handle_printf_atsign (FILE *stream,
int i, start, stop, step; int i, start, stop, step;
NSRange range; NSRange range;
/* xxx check to make sure aRange is within self; raise NSStringBoundsError */ i = [self length];
assert(NSMaxRange(aRange) <= [self length]); if (aRange.location > i)
[NSException raise: NSRangeException format:@"Invalid location."];
if (aRange.length > (i - aRange.location))
[NSException raise: NSRangeException format:@"Invalid location+length."];
if ((mask & NSBackwardsSearch) == NSBackwardsSearch) if ((mask & NSBackwardsSearch) == NSBackwardsSearch)
{ {
@ -1977,8 +1980,12 @@ else
{ {
int len, count; int len, count;
/* xxx check to make sure aRange is within self; raise NSStringBoundsError */ len = [self cStringLength];
assert(NSMaxRange(aRange) <= [self cStringLength]); if (aRange.location > len)
[NSException raise: NSRangeException format:@"Invalid location."];
if (aRange.length > (len - aRange.location))
[NSException raise: NSRangeException format:@"Invalid location+length."];
if (maxLength < aRange.length) if (maxLength < aRange.length)
{ {
len = maxLength; len = maxLength;
@ -2159,8 +2166,12 @@ else
NSString * last_compo = [self lastPathComponent]; NSString * last_compo = [self lastPathComponent];
NSString * tmp_path; NSString * tmp_path;
NSDirectoryEnumerator * e; NSDirectoryEnumerator * e;
NSMutableArray *op;
int match_count = 0; int match_count = 0;
if (outputArray != 0)
op = (NSMutableArray*)[NSMutableArray array];
if (outputName != NULL) *outputName = nil; if (outputName != NULL) *outputName = nil;
if ([base_path length] == 0) base_path = @"."; if ([base_path length] == 0) base_path = @".";
@ -2189,12 +2200,14 @@ else
/* Found a completion */ /* Found a completion */
match_count++; match_count++;
if (outputArray != NULL) if (outputArray != NULL)
[*outputArray addObject: tmp_path]; [*op addObject: tmp_path];
if ((outputName != NULL) && if ((outputName != NULL) &&
((*outputName == nil) || (([*outputName length] < [tmp_path length])))) ((*outputName == nil) || (([*outputName length] < [tmp_path length]))))
*outputName = tmp_path; *outputName = tmp_path;
} }
if (outputArray != NULL)
*outputArray = [[op copy] autorelease];
return match_count; return match_count;
} }