Question

When I run my code through the version 252 checker binary, there are no analysis errors. However, when I change to use the latest 253 checker, it returns a slew of errors, all of which do not make any sense. For example, here is an image of an error that it shows in my Safari browser after the scan-build script is complete:

Clang static analyzer error

This is a pretty common error that shows up in the error listing. As you can see, the method name has Copy at the end of it, but it is still reporting as incorrectly named.

Here is the breakdown of errors that I am now getting with checker version 253:

Bug Summary

Results in this analysis run are based on analyzer build checker-253.

Bug Type    Quantity
All Bugs    83  

Dead code   
Unreachable code    17  

Memory (Core Foundation/Objective-C)    
Bad release 19  
Leak of returned object 23  
Object sent -autorelease too many times 24

The autorelease errors seem to be related to the fact that the analyzer is unable to see that the Copy methods are actually correctly named, and I tried to look for an example of unreachable code, but I could not really find any patterns or explanations of those errors, as the errors were all lines of code inside simple if statements. Here is one for example:

Yet another Clang analyzer error

I suppose that this could be some bugs that were introduced in the latest version of checker that is causing these to show up as errors. Is there something else (some kind of build setting or issue with the scan-build script) that I could be missing here?

Was it helpful?

Solution

First, method names should start with lower case letters, not uppercase (save for abbreviations like URL). It may be that the static analyzer is tripping over the uppercase "Get".

Next, even with a lowercase "get", the method does not follow convention.

To quote the documentation:

Use “get” only for methods that return objects and values indirectly. You should use this form for methods only when multiple items need to be returned.

Thus, the analyzer is correctly identifying an issue.

I would suggest following the guidelines and using something like:

+ (NSArray *) modifiedOrNewPeople: (FMDatabase *) aDatabase;

Which would release an autoreleased array. If there is some reason you can't return an autoreleased object, please comment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top