the clang analyzer is awesome!
the clang analyzer is awesome!
- Subject: the clang analyzer is awesome!
- From: Matt Neuburg <email@hidden>
- Date: Tue, 09 Apr 2013 08:52:32 -0700
I just did an Analyze on my project. At first I thought the analyzer had gone nuts. It drew this amazingly complicated diagram through my code, and kept talking about the potential leak of an object that I knew for a fact wasn't leaking (the CFRelease was right there). But after a while I realized that the analyzer was really telling me that I wasn't covering all my bases. I was saying this:
CGImageSourceRef src;
if ([imageSource isKindOfClass:[NSURL class]])
src = CGImageSourceCreateWithURL((__bridge CFURLRef)imageSource, nil);
if ([imageSource isKindOfClass:[NSData class]])
src = CGImageSourceCreateWithData((__bridge CFDataRef)imageSource, nil);
Now, *I* knew that this covered all my bases. But the analyzer didn't know; and hey, it's right, because my code might be called by some idiot (my future self). I was able to quiet the analyzer's fears, and backstop the situation, by rewriting like this:
CGImageSourceRef src = NULL;
if ([imageSource isKindOfClass:[NSURL class]])
src = CGImageSourceCreateWithURL((__bridge CFURLRef)imageSource, nil);
else if ([imageSource isKindOfClass:[NSData class]])
src = CGImageSourceCreateWithData((__bridge CFDataRef)imageSource, nil);
else
return; // should never happen!
Looking at the complexity of the execution path that the analyzer had to trace *and draw* in my code, my jaw was on the floor. Amazing. Who *wrote* this thing?? Bravo, whoever it was. m.
--
matt neuburg, phd = email@hidden, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden