clang-static-analyzer

Clang Error on "Potential null dereference."

I keep getting Clang errors on the following type of code and I can't figure out why they're erroneous or how to resolve them to Clang's satisfaction: + (NSString *)checkForLength:(NSString *)theString error:(NSError **)error { BOOL hasLength = ([theString length] > 0); if (hasLength) { return theString; } else ...

How to get this Apple Script for Clang Static Analyzer working with Xcode?

Here's a script where lots of people say it's good: http://allancraig.net/blog/?p=381 But I can't get it to work. What are the steps I have to do with the Xcode script editor, to run that script? I have pasted it in "Script Editor.app", that Script Editor app from Mac OSx and saved it as clang.scpt. Then, I went to Xcode and opened t...

In Xcode 3.2 under iPhone-SDK 3.1, how do I avoid "Dead store" error from CLANG analyzer?

I just upgraded to Xcode 3.2 and am using the Build and Analyze feature to check old code for errors. While doing something I thought was innocuous, I get this error: "Dead store: Value stored to 'newBook' during it's initialization is never read in SpellTest.m" #define kSpellBookFilename @"TestBookSaver" -(void)testBookLoadFromDisk...

Is it wise to use Clang to start with?

I am just starting out with xcode and learning Objective-C & Cocoa, would it be helpful to swap the compiler in Xcode 3.2 to Clang for the enhanced error checking and static analyser. I am just curious if the extras given would be helpful or would my learning be better served sticking to the default settings? many thanks gary ...

Clang: what is "Method returns an Objective-C object with a +0 retain count" trying to tell me?

Running a static analysis with clang in both XCode 3.2 and Nikita Zhuk's Analysis Tool I've often come across this pair of warnings: Method returns an Objective-C object with a +0 retain count (non-owning reference) Incorrect decrement of the reference count of an object is not owned at this point by the caller An example of c...

Clang static analyzer on Windows

Does anybody have any success running clang static analyzer on Windows? I have successfully built llvm and clang (using VS 2008). Running scan-build results in the following error: The getpwuid function is unimplemented at scan-build line 35. Some research shows that getpwuid is not supported on Windows platforms. ...

Interpreting clang static analyzer messages

Why does the Clang Static Analyzer (CSA) output the following message: Although the value stored to 'self' is used in the enclosing expression, the value is never actually read from 'self' for the following method: - (id)init { return (self = [super initWithStyle:UITableViewStyleGrouped]); } The code works as expected,...

Clang static analyzer gives warning over autoreleased

result = [result stringByReplacingOccurrencesOfString:@"ç" withString:@"c"]; result = [result stringByReplacingOccurrencesOfString:@"Ç" withString:@"c"]; clang Static analyzer gives warning "Method returns an Objective-C object with a +0 retain count (non-owning reference)" return [result autorelease]; " Object over-autoreleased: o...

Does Clang-LLVM work for iPhone?

I am currently using Xcode 3.2.1 for learning the iPhone SDK and was wondering if its possible to use the Clang-LLVM and the static-analyser to aid in debugging my code. Currently I am using the default templates, but swapping the compiler in project>settings gives me errors when compiling for the simulator. Is this possible? gary ...

Why's the Build and Analyze command not finding obvious memory management errors?

For some reason, the Clang Static Analyzer in my Xcode doesn't complain about anything. I made big memory management mistakes to try it (alloc and no release), but it never finds them and doesn't complain about them. Even after clean all targets and again Build and Analyze. I was building for Simulator 3.1 Must I set that up specifical...

Figuring Out Memory Leaks without Clang

I'm trying to see if I can find some leaks myself in Apple's TopSongs app. Can someone help me out in at least one and how to identify what is in the Leaks reports and how I can get an idea on finding them? ie: I got one like this: # Category Event Type Timestamp Address Size Responsible Library Responsible Caller 0 Gener...

Clang Static Analyzer for xcode for dummies

Hi, Could somebody please help me get Clang up and running? (I don't have 3.2) I've followed numerous tutorials (basically every link off of this page http://stackoverflow.com/questions/961844/using-clang-static-analyzer-from-within-xcode) but I just cant get it to work! The only thing I've managed to do successfully so far is downloa...

CLang error (objective C): value stored during initialization is never read

Foo *oFoo = [[[Foo alloc] init] autorelease]; This is how I was taught to program in Objective C, yet the CLang error checker complains that the initial value was never read. But oFoo is an object with properties. oFoo itself has no single value. The property values are what matter. oFoo.PropertyA = 1; oFoo.PropertyB = @"Hello, World....

Xcode 3.2: Build & Analyze never finds any issues

I've used the Clang Static Analyzer from the command line before. I wanted to try Xcode's built-in version via Build & Analyze. I never get any negative results even though i specially prepared my code with very obvious issues Clang was always able to point out: // over-releasing an object: [label release]; [label release]; ...

Is the scope of what Xcode's "Build and Analyze" will catch as a leak supposed to be this limited?

It doesn't care about this: NSString* leaker() { return [[NSString alloc] init]; } I thought it would have been smart enough to check if any code paths could call that function without releasing its return value (I wouldn't normally code this way, I'm just testing the analyzer). It reports this as a leak: NSString* leaker() { NSSt...

How can I fix this clang warning: "Object with +0 retain counts returned to caller where +1 (owning) retain count is expected"?

I have a piece of Objective-C code that looks like the following: - (NSString *)copyData:(NSData *)data { NSString *path = [[[self outputDirectory] stringByAppendingPathComponent:@"archive"] stringByAppendingPathExtension:@"zip"]; NSLog(@"Copying data to %@", path); [data writeToFile:path atomically:NO]; return path; } ...

LLVM/Clang bug found in convenience method and NSClassFromString(...) alloc/release

I am analyzing Objective-C iPhone project with LLVM/Clang static analyzer. I keep getting two reported bugs, but I am pretty sure that the code is correct. 1) Convenience method. + (UILabel *)simpleLabel { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 200, 25)]; label.adjustsFontSizeToFitWidth = YES; [label ...

XCode/Static Analyzer: Suppressing a retain count/leak warning

Hi all, I have a function that is creating a variable, but not deallocating it. It passes this object on with a message to another function that deals with the memory management. My question is how do I suppress the static analyzer warning for what XCode thinks is an over-retained variable? I thought I could use NS_RETURNS_RETAINED f...

Don't understand memory analysis

Hi, I have upgraded my XCode to versio 3.2.3 to support iOS4 on my iphone project. using the static analyser I checked for memory management problems. In one of my routines I get the following problem: I generate a user alert after adding an event to the calendar to give him a status. This runs fine, but the memory analyser doesn't li...

Using an external Xcode Clang Static Analyzer binary, with additional checks

I’m using Xcode 3.2.4 and have setup the Clang Static Analyser feature to use a newer build of the binary, as detailed here: http://clang-analyzer.llvm.org/xcode.html (Basically using the set-xcode-analyzer command line utility to change which copy of the Static Analyser that Xcode uses for Build and Analyze.) What I can’t figure is ho...