tweaks for clang static analyser warningS

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32048 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2011-02-11 09:02:33 +00:00
parent d6502819c8
commit 53e8554a8c
6 changed files with 34 additions and 19 deletions

View file

@ -1,3 +1,14 @@
2011-02-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSUserDefaults.m:
* Source/NSArray.m:
* Source/NSString.m:
* Source/NSPointerArray.m:
* Tools/AGSParser.m:
Tweaks to try to avoid clang analyser warnings.
* Source/NSPropertyList.m:
Revert last change.
2011-02-11 Stefan Bidigaray <stefanbidi@gmail.com> 2011-02-11 Stefan Bidigaray <stefanbidi@gmail.com>
* Source/NSDateFormatter.m: Avoid multiple memory copy operations. * Source/NSDateFormatter.m: Avoid multiple memory copy operations.

View file

@ -1093,11 +1093,11 @@ compare(id elem1, id elem2, void* context)
{ {
NSMutableArray *sortedArray; NSMutableArray *sortedArray;
sortedArray = [[NSMutableArrayClass allocWithZone: sortedArray = [[[NSMutableArrayClass allocWithZone:
NSDefaultMallocZone()] initWithArray: self copyItems: NO]; NSDefaultMallocZone()] initWithArray: self copyItems: NO] autorelease];
[sortedArray sortUsingFunction: comparator context: context]; [sortedArray sortUsingFunction: comparator context: context];
return AUTORELEASE([sortedArray makeImmutableCopyOnFail: NO]); return [sortedArray makeImmutableCopyOnFail: NO];
} }
/** /**
@ -1107,8 +1107,9 @@ compare(id elem1, id elem2, void* context)
- (NSString*) componentsJoinedByString: (NSString*)separator - (NSString*) componentsJoinedByString: (NSString*)separator
{ {
unsigned int c = [self count]; unsigned int c = [self count];
NSMutableString *s = [[NSMutableString alloc] initWithCapacity: c]; NSMutableString *s;
s = [[[NSMutableString alloc] initWithCapacity: c] autorelease];
if (c > 0) if (c > 0)
{ {
unsigned l = [separator length]; unsigned l = [separator length];
@ -1124,7 +1125,7 @@ compare(id elem1, id elem2, void* context)
[s appendString: [[self objectAtIndex: i] description]]; [s appendString: [[self objectAtIndex: i] description]];
} }
} }
return AUTORELEASE([s makeImmutableCopyOnFail: NO]); return [s makeImmutableCopyOnFail: NO];
} }
/** /**
@ -1135,7 +1136,7 @@ compare(id elem1, id elem2, void* context)
- (NSArray*) pathsMatchingExtensions: (NSArray*)extensions - (NSArray*) pathsMatchingExtensions: (NSArray*)extensions
{ {
unsigned i, c = [self count]; unsigned i, c = [self count];
NSMutableArray *a = [[NSMutableArray alloc] initWithCapacity: 1]; NSMutableArray *a = [[[NSMutableArray alloc] initWithCapacity: 1] autorelease];
Class cls = [NSString class]; Class cls = [NSString class];
IMP get = [self methodForSelector: oaiSel]; IMP get = [self methodForSelector: oaiSel];
IMP add = [a methodForSelector: addSel]; IMP add = [a methodForSelector: addSel];
@ -1152,7 +1153,7 @@ compare(id elem1, id elem2, void* context)
} }
} }
} }
return AUTORELEASE([a makeImmutableCopyOnFail: NO]); return [a makeImmutableCopyOnFail: NO];
} }
/** /**

View file

@ -261,8 +261,7 @@ static Class concreteClass = Nil;
[a addObject: (id)_contents[i]]; [a addObject: (id)_contents[i]];
} }
} }
[a makeImmutableCopyOnFail: NO]; return [a makeImmutableCopyOnFail: NO];
return a;
} }
} }

View file

@ -1781,13 +1781,13 @@ handle_printf_atsign (FILE *stream,
{ {
id copy; id copy;
copy = [[GSMutableStringClass allocWithZone: NSDefaultMallocZone()] copy = [[[GSMutableStringClass allocWithZone: NSDefaultMallocZone()]
initWithString: self]; initWithString: self] autorelease];
[copy replaceOccurrencesOfString: replace [copy replaceOccurrencesOfString: replace
withString: by withString: by
options: opts options: opts
range: searchRange]; range: searchRange];
return [[copy makeImmutableCopyOnFail: NO] autorelease]; return [copy makeImmutableCopyOnFail: NO];
} }
- (NSString*) stringByReplacingOccurrencesOfString: (NSString*)replace - (NSString*) stringByReplacingOccurrencesOfString: (NSString*)replace
@ -1809,10 +1809,10 @@ handle_printf_atsign (FILE *stream,
{ {
id copy; id copy;
copy = [[GSMutableStringClass allocWithZone: NSDefaultMallocZone()] copy = [[[GSMutableStringClass allocWithZone: NSDefaultMallocZone()]
initWithString: self]; initWithString: self] autorelease];
[copy replaceCharactersInRange: aRange withString: by]; [copy replaceCharactersInRange: aRange withString: by];
return [[copy makeImmutableCopyOnFail: NO] autorelease]; return [copy makeImmutableCopyOnFail: NO];
} }
/** /**

View file

@ -1908,7 +1908,7 @@ NSLog(@"Creating empty user defaults database");
[_lock lock]; [_lock lock];
NS_DURING NS_DURING
{ {
if (_dictionaryRep == nil) if (nil == _dictionaryRep)
{ {
NSEnumerator *enumerator; NSEnumerator *enumerator;
NSMutableDictionary *dictRep; NSMutableDictionary *dictRep;
@ -1925,8 +1925,8 @@ NSLog(@"Creating empty user defaults database");
enumerator = [_searchList reverseObjectEnumerator]; enumerator = [_searchList reverseObjectEnumerator];
nImp = [enumerator methodForSelector: nextObjectSel]; nImp = [enumerator methodForSelector: nextObjectSel];
dictRep = [NSMutableDictionaryClass allocWithZone: NSDefaultMallocZone()]; dictRep = [NSMutableDictionaryClass alloc];
dictRep = [dictRep initWithCapacity: 512]; dictRep = [[dictRep initWithCapacity: 512] autorelease];
addImp = [dictRep methodForSelector: addSel]; addImp = [dictRep methodForSelector: addSel];
while ((obj = (*nImp)(enumerator, nextObjectSel)) != nil) while ((obj = (*nImp)(enumerator, nextObjectSel)) != nil)
@ -1939,7 +1939,10 @@ NSLog(@"Creating empty user defaults database");
} }
_dictionaryRep = [dictRep makeImmutableCopyOnFail: NO]; _dictionaryRep = [dictRep makeImmutableCopyOnFail: NO];
} }
rep = [[_dictionaryRep retain] autorelease]; else
{
rep = [[_dictionaryRep retain] autorelease];
}
[_lock unlock]; [_lock unlock];
} }
NS_HANDLER NS_HANDLER

View file

@ -2189,6 +2189,7 @@ fail:
*/ */
[self skipUnit]; [self skipUnit];
DESTROY(comment); DESTROY(comment);
RELEASE(arp);
return [NSMutableDictionary dictionary]; return [NSMutableDictionary dictionary];
} }
else else