• 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: Logical and - second operator evaluated?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Logical and - second operator evaluated?


  • Subject: Re: Logical and - second operator evaluated?
  • From: Sam Schapmann <email@hidden>
  • Date: Mon, 02 Mar 2009 19:12:43 -0600

Have you checked that you have initialized the "timer" pointer to nil? Like C, in Objective-C local variables (as opposed to instance variables) are allocated on the stack frame and have unspecified initial values. About the only thing you can count on for sure is that the initial value is NOT nil (i.e. 0x0).

So, if your code is structured like the below snippet, then I would expect BAD_ACCESS every time. That's because the first check is TRUE (timer indeed is not nil), and the second check has the side effect of attempting to invoke the isValid method at a memory location that is 1) random, and 2) certainly not even an Obj-C object. The BAD ACCESS would result from the Obj-C runtime attempting to dereference the timer pointer out to no-man's memory land.

Instance variables and static variables are initialized to bitwise 0's, so the above analysis would not apply in that case.

Just some thoughts.

-S

-(void)aMethod
{
   NSTimer *timer;
 if(timer!=nil && [timer isValid]) [timer invalidate];
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Latent objects remain associated in NSTokenField after they are deleted/removed?
  • Next by Date: Re: Exel and PowerPoint (??????? ???????)
  • Previous by thread: Re: Logical and - second operator evaluated?
  • Next by thread: How do I pop/release from within a subView back to my original/calling routine?
  • Index(es):
    • Date
    • Thread