• 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: odd behavior with NSError?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: odd behavior with NSError?


  • Subject: Re: odd behavior with NSError?
  • From: Ben Trumbull <email@hidden>
  • Date: Thu, 15 Oct 2009 23:45:31 -0700

(response is pedantic for the purposes of the archive :)

even more better flaming pedanticism!

On Oct 15, 2009, at 10:41 PM, Nathan Vander Wilt wrote:

Ouch. So the following pattern is incorrect?

Yes; it is incorrect.

NSError* internalError = nil;
(void)[foo somethingReturningBool:bar error:&internalError];
if (internalError) {
  // ...
}

Specifically, assuming anything about the value of 'internalError' without first determining the return value of - somethingReturningBool:error: returned a value indicating an error (typically NO/0/nil/NULL) is an error.

The specific issue is failing to check the return value of the method before touching the internalError value. You MUST check it.


However, the documentation also encourages not assigning nil to local NSError* declarations. Not initializing locals is imho, professionally, realistically, and morally wrong. It's just a bug waiting to happen. And you have to know it is, just looking at it. Whatever might have been saved / gained by not initializing them was wasted, for all of time, the first time I had to debug the segfault. Which I did, like an idiot, a long time ago.

Let me just say I really especially appreciated the time spent debugging other people not initializing their locals. It wasn't visions of sugar plums.

Other people have different perspectives on local variable initialization. Wrong perspectives, but different. Fortunately now, they waste their arguments upon the merciless <http://llvm.org/img/DragonFull.png >

- Ben

_______________________________________________

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


  • Follow-Ups:
    • Re: odd behavior with NSError?
      • From: Rob Keniger <email@hidden>
  • Prev by Date: Re: odd behavior with NSError?
  • Next by Date: Re: Programming Style: Method Definition with or without a semicolon.
  • Previous by thread: Re: odd behavior with NSError?
  • Next by thread: Re: odd behavior with NSError?
  • Index(es):
    • Date
    • Thread