• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
the clang analyzer is awesome!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: the clang analyzer is awesome!
      • From: Rick Mann <email@hidden>
    • Re: the clang analyzer is awesome!
      • From: Seth Willits <email@hidden>
  • Prev by Date: Re: Provisioning Profiles
  • Next by Date: Re: Provisioning Profiles
  • Previous by thread: Re: Provisioning Profiles
  • Next by thread: Re: the clang analyzer is awesome!
  • Index(es):
    • Date
    • Thread