From 3f15443f989a131cd74b70fbfb60defc3f9bdf03 Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 9 Mar 2011 12:40:50 +0000 Subject: [PATCH] a few more static analyser tweaks git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32517 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Headers/Foundation/NSSpellServer.h | 4 ++-- Source/Additions/Unicode.m | 1 - Source/GSAvahiClient.m | 6 ++++-- Source/GSAvahiNetService.m | 3 ++- Source/NSNetServices.m | 18 ++++++++++++------ Source/NSPropertyList.m | 6 +++--- Source/NSRunLoop.m | 3 +-- Source/NSSocketPort.m | 2 -- Source/NSSocketPortNameServer.m | 11 ++--------- Source/NSTimeZone.m | 2 +- Source/NSUnarchiver.m | 6 +----- Tools/HTMLLinker.m | 5 ++--- Tools/cvtenc.m | 4 ++-- Tools/sfparse.m | 4 ++-- 15 files changed, 41 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index ec779f83d..5be923b07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,13 @@ * Source/NSUserDefaults.m: Fix bug in resetting ... was ending up with an immutable dictionary for the registration domain. + * Source/NSObject.m: fix references to isa. + * Source/NSPropertyList.m: Fix unused increments. + * Source/NSRunLoop.m: Remove unused code. + * Source/NSSocketPort.m: Remove unused code. + * Source/NSSocketPortNameServer.m: Remove unused code. + * Source/NSTimeZone.m: Fix unused increment. + * Source/NSUnarchiver.m: Fix unused assignment. 2011-03-08 Richard Frith-Macdonald diff --git a/Headers/Foundation/NSSpellServer.h b/Headers/Foundation/NSSpellServer.h index 11c5c7590..3568a8679 100644 --- a/Headers/Foundation/NSSpellServer.h +++ b/Headers/Foundation/NSSpellServer.h @@ -58,8 +58,8 @@ GS_EXPORT NSString *const NSGrammarUserDescription; #if GS_EXPOSE(NSSpellServer) @private id _delegate; - BOOL _caseSensitive; - unsigned char _dummy[3]; + BOOL _caseSensitive GS_UNUSED_IVAR; + unsigned char _dummy[3] GS_UNUSED_IVAR; NSMutableDictionary *_userDictionaries; NSString *_currentLanguage; NSArray *_ignoredWords; diff --git a/Source/Additions/Unicode.m b/Source/Additions/Unicode.m index 19557344b..00cce04ec 100644 --- a/Source/Additions/Unicode.m +++ b/Source/Additions/Unicode.m @@ -2274,7 +2274,6 @@ tables: * No mapping has been found. */ result = NO; - spos = slen; goto done; } } diff --git a/Source/GSAvahiClient.m b/Source/GSAvahiClient.m index a733db514..a6e32614d 100644 --- a/Source/GSAvahiClient.m +++ b/Source/GSAvahiClient.m @@ -119,8 +119,9 @@ GSAvahiClientState(AvahiClient *client, AvahiClientState state, void *userInfo) - (id) initWithRunLoop: (NSRunLoop*)rl forMode: (NSString*)mode { - return [self avahiClientInitWithRunLoop: rl + self = [self avahiClientInitWithRunLoop: rl forMode: mode]; + return self; } - (id) avahiClientInit @@ -131,7 +132,8 @@ GSAvahiClientState(AvahiClient *client, AvahiClientState state, void *userInfo) - (id) init { - return [self avahiClientInit]; + self = [self avahiClientInit]; + return self; } - (void*) client diff --git a/Source/GSAvahiNetService.m b/Source/GSAvahiNetService.m index 4ff534b63..1fa19d134 100644 --- a/Source/GSAvahiNetService.m +++ b/Source/GSAvahiNetService.m @@ -1005,7 +1005,8 @@ didUpdateRecordData: (id)data } else { - ret = AVAHI_ERR_FAILURE; + ret = AVAHI_ERR_FAILURE; + break; } } diff --git a/Source/NSNetServices.m b/Source/NSNetServices.m index dff0cbcfe..64da53bde 100644 --- a/Source/NSNetServices.m +++ b/Source/NSNetServices.m @@ -45,7 +45,9 @@ NSString * const NSNetServicesErrorCode = @"NSNetServicesErrorCode"; */ NSString * const NSNetServicesErrorDomain = @"NSNetServicesErrorDomain"; +static Class abstractServiceClass; static Class concreteServiceClass; +static Class abstractBrowserClass; static Class concreteBrowserClass; @implementation NSNetService @@ -53,6 +55,7 @@ static Class concreteBrowserClass; { if (self == [NSNetService class]) { + abstractServiceClass = self; # if GS_USE_AVAHI==1 concreteServiceClass = [GSAvahiNetService class]; # else @@ -63,9 +66,10 @@ static Class concreteBrowserClass; + (id) allocWithZone: (NSZone*)zone { - // Note: Assignging the subclass to self will make NSObject allocate the - // correct class layout. - self = concreteServiceClass; + if (self == abstractServiceClass) + { + return [concreteServiceClass allocWithZone: zone]; + } return [super allocWithZone: zone]; } @@ -386,6 +390,7 @@ static Class concreteBrowserClass; { if (self == [NSNetServiceBrowser class]) { + abstractBrowserClass = self; # if GS_USE_AVAHI==1 concreteBrowserClass = [GSAvahiNetServiceBrowser class]; # else // Not Avahi (=GS_USE_MDNS) @@ -396,9 +401,10 @@ static Class concreteBrowserClass; + (id) allocWithZone: (NSZone*)zone { - // Note: Assignging the subclass to self will make NSObject allocate the - // correct class layout. - self = concreteBrowserClass; + if (self == abstractBrowserClass) + { + return [concreteBrowserClass allocWithZone: zone]; + } return [super allocWithZone: zone]; } - (id) init diff --git a/Source/NSPropertyList.m b/Source/NSPropertyList.m index b0600bccc..5e873a783 100644 --- a/Source/NSPropertyList.m +++ b/Source/NSPropertyList.m @@ -1570,7 +1570,7 @@ PString(NSString *obj, NSMutableData *output) break; } } - *ptr++ = '"'; + *ptr = '"'; GS_ENDITEMBUF(); } @@ -1921,7 +1921,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step, dst[++j] = ' '; } } - dst[j++] = '>'; + dst[j] = '>'; } } else if ([obj isKindOfClass: NSDateClass]) @@ -2186,7 +2186,7 @@ OAppend(id obj, NSDictionary *loc, unsigned lev, unsigned step, comp = (NSComparisonResult (*)(id, SEL, id)) [a methodForSelector: @selector(compare:)]; } - r = (*comp)(a, @selector(compare:), b); + r = (0 == comp) ? 0 : (*comp)(a, @selector(compare:), b); if (r < 0) { #ifdef GSWARN diff --git a/Source/NSRunLoop.m b/Source/NSRunLoop.m index 117b28691..acb3f262e 100644 --- a/Source/NSRunLoop.m +++ b/Source/NSRunLoop.m @@ -915,7 +915,6 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now) ti += (increment * add); if (ti < now) { - add++; ti += increment; } } @@ -1099,7 +1098,7 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now) #endif NSDebugMLLog(@"NSRunLoop", @"limit date %f in %@", - [when timeIntervalSinceReferenceDate], mode); + nil == when ? 0.0 : [when timeIntervalSinceReferenceDate], mode); } return when; } diff --git a/Source/NSSocketPort.m b/Source/NSSocketPort.m index dbfdcd412..0cf89c8e8 100644 --- a/Source/NSSocketPort.m +++ b/Source/NSSocketPort.m @@ -252,14 +252,12 @@ decodePort(NSData *data, NSString *defaultAddress) GSPortInfo *pi; NSString *addr; uint16_t pnum; - uint32_t length; NSHost *host; unichar c; pih = (GSPortItemHeader*)[data bytes]; NSCAssert(GSSwapBigI32ToHost(pih->type) == GSP_PORT, NSInternalInconsistencyException); - length = GSSwapBigI32ToHost(pih->length); pi = (GSPortInfo*)&pih[1]; pnum = GSSwapBigI16ToHost(pi->num); if (strncmp(pi->addr, "VER", 3) == 0) diff --git a/Source/NSSocketPortNameServer.m b/Source/NSSocketPortNameServer.m index 768cf738c..5cda4e9d9 100644 --- a/Source/NSSocketPortNameServer.m +++ b/Source/NSSocketPortNameServer.m @@ -656,7 +656,6 @@ typedef enum { [serverLock lock]; NS_DURING { - GSPortCom *tmp; NSData *dat; [com startListNameServers]; @@ -683,9 +682,7 @@ typedef enum { [NSException raise: NSInternalInconsistencyException format: @"failed to get list of name servers"]; } - tmp = com; - com = nil; - RELEASE(tmp); + RELEASE(com); } NS_HANDLER { @@ -1083,8 +1080,6 @@ typedef enum { NS_DURING { - GSPortCom *tmp; - com = [GSPortCom new]; [com startPortUnregistration: 0 withName: name]; while ([limit timeIntervalSinceNow] > 0 && [com isActive] == YES) @@ -1134,9 +1129,7 @@ typedef enum { } } } - tmp = com; - com = nil; - RELEASE(tmp); + RELEASE(com); } NS_HANDLER { diff --git a/Source/NSTimeZone.m b/Source/NSTimeZone.m index 495177a0b..77b06239d 100644 --- a/Source/NSTimeZone.m +++ b/Source/NSTimeZone.m @@ -308,7 +308,7 @@ decode (const void *ptr) result = (result << 8) | *p++; result = (result << 8) | *p++; result = (result << 8) | *p++; - result = (result << 8) | *p++; + result = (result << 8) | *p; return result; #endif /* defined(WORDS_BIGENDIAN) && SIZEOF_INT == 4 */ } diff --git a/Source/NSUnarchiver.m b/Source/NSUnarchiver.m index 3ee525e42..bcba07d22 100644 --- a/Source/NSUnarchiver.m +++ b/Source/NSUnarchiver.m @@ -753,7 +753,7 @@ static Class NSDataMallocClass; className = @"_NSUnarchiverUnknownClass"; } classInfo = [objDict objectForKey: className]; - if (classInfo == nil) + if (nil == classInfo) { classInfo = [NSUnarchiverObjectInfo newWithName: className]; c = NSClassFromString(className); @@ -770,10 +770,6 @@ static Class NSDataMallocClass; [objDict setObject: classInfo forKey: className]; RELEASE(classInfo); } - else - { - c = classInfo->class; - } RELEASE(className); classInfo->version = (NSInteger)cver; GSIArrayAddItem(clsMap, (GSIArrayItem)((id)classInfo)); diff --git a/Tools/HTMLLinker.m b/Tools/HTMLLinker.m index 095506326..94dd6de71 100644 --- a/Tools/HTMLLinker.m +++ b/Tools/HTMLLinker.m @@ -790,7 +790,7 @@ static int verbose = 0; NSString *filename; e = [HTMLDirectoryEnumerator alloc]; - e = [e initWithBasePath: pathOnDisk]; + e = [[e initWithBasePath: pathOnDisk] autorelease]; [e setLooksForHTMLLinkFiles: YES]; [e setReturnsAbsolutePaths: YES]; @@ -1125,7 +1125,7 @@ int main (int argc, char** argv, char** env) NSArray *args; NSMutableArray *inputFiles; unsigned i, count; - BOOL warn, fixupAllLinks; + BOOL warn; NSString *linksMarker; HTMLLinker *linker; CREATE_AUTORELEASE_POOL(pool); @@ -1152,7 +1152,6 @@ int main (int argc, char** argv, char** env) nil]]; warn = [userDefs boolForKey: @"Warn"]; - fixupAllLinks = [userDefs boolForKey: @"FixupAllLinks"]; linksMarker = [userDefs stringForKey: @"LinksMarker"]; diff --git a/Tools/cvtenc.m b/Tools/cvtenc.m index 609bf5057..8cfd89cea 100644 --- a/Tools/cvtenc.m +++ b/Tools/cvtenc.m @@ -285,8 +285,8 @@ main(int argc, char** argv, char **env) } } NSZoneFree(z, u); - myData = [[NSData alloc] initWithBytesNoCopy: c - length: o]; + myData = [[[NSData alloc] + initWithBytesNoCopy: c length: o] autorelease]; } else if (eIn == YES) { diff --git a/Tools/sfparse.m b/Tools/sfparse.m index 05a6f6b0e..c7505fede 100644 --- a/Tools/sfparse.m +++ b/Tools/sfparse.m @@ -50,8 +50,8 @@ convert_unicode(NSArray *args) IF_NO_GC([myString autorelease];) if ([myString length] == 0) { - myString = [[NSString alloc] initWithData: data - encoding: [NSString defaultCStringEncoding]]; + myString = [[[NSString alloc] initWithData: data + encoding: [NSString defaultCStringEncoding]] autorelease]; } output = [[file lastPathComponent] stringByAppendingPathExtension: @"unicode"];