I keep getting Clang errors in the following type of code, and I can't figure out why they are wrong or how to solve them to satisfy Clang:
+ (NSString *)checkForLength: (NSString *)theString error: (NSError **)error { BOOL hasLength = ([theString length] > 0); if (hasLength) return theString; else { *error = [NSError errorWithDomain:@"ErrorDomain" code:hasLength userInfo:nil]; return nil; } }
Leaving aside the completely far-fetched nature of the example (which Klang made so that it was illustrative enough), Klang refuses the error assignment line with the following objection:
Potential zero dereferencing. According to coding standards, in the section "Creating and returning NSError objects", the parameter "error" can be zero.
I like to have a clean Clang report. I read the cited document, and I see no way to do what was expected; I checked out some Cocoa open source libraries and this seems to be a common idiom. Any ideas?
cocoa clang-static-analyzer
bbrown Jul 27 '09 at 17:28 2009-07-27 17:28
source share