• 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
Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?


  • Subject: Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 25 Feb 2014 11:28:50 -0800

On Feb 25, 2014, at 10:53 , Jeff Evans <email@hidden> wrote:

I'm interested in knowing what the flaw is.

It’s a little bit subtle, because the power of suggestion hides a really simple flaw:

if (_weakIVar)
[_weakIVar someMessage];

The flaw is that _weakIVar can become nil *after* the if-test and *before* the message send. You could be sending a message to nil in spite of the if-test.  In other words, the if-test does precisely nothing.

The power of suggestion comes into it because, when you read the if-test, you tend to believe it does what it appears to do.

The flaw is harmless in this simple example, but in a more complicated sequence:

if (_weakIVar)
{
…
[_weakIVar salvageAllHumanKnowledge];
[self destroyThePlanet];
}

the outcome might not be what you intended.

 _______________________________________________
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: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?
      • From: Jeff Evans <email@hidden>
References: 
 >What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from? (From: David Hoerl <email@hidden>)
 >Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from? (From: Quincey Morris <email@hidden>)
 >Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from? (From: Jeff Evans <email@hidden>)

  • Prev by Date: Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?
  • Next by Date: Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?
  • Previous by thread: Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?
  • Next by thread: Re: What does the CLANG_WARN_OBJC_RECEIVER_WEAK warning protect us from?
  • Index(es):
    • Date
    • Thread