Re: NSUserUnixTask and com.apple.foundation.UserScriptService crash
Re: NSUserUnixTask and com.apple.foundation.UserScriptService crash
- Subject: Re: NSUserUnixTask and com.apple.foundation.UserScriptService crash
- From: Fritz Anderson <email@hidden>
- Date: Sat, 01 Dec 2012 16:44:18 -0600
On 1 Dec 2012, at 4:13 PM, "email@hidden" <email@hidden> wrote:
> NSURL *scriptsFolderURL = [[NSFileManager defaultManager]
...
> error:error];
>
> if (*error) {
> MLogInfo(@"Error: %@", *error);
...
Stop.
Go no further till you fix this. The return-by-reference NSError variable is NEVER, EVER* an indication that the call that returns it failed. The API does not guarantee (as you seem to assume) that *error will be nilled-out on success; in fact, the general rule kind of promises that it _won't_. It may still contain the garbage you passed in. It may be a scratch NSError object that the callee filled in as a contingency — so even if you nil-out *error yourself, it may be non-nil even if the method succeeded.
* (I believe there are a couple of methods that do use the indirect NSError as the error indicator, but I've forgotten what they are, and they are mistakes.)
The _only_ indication that a method failed is its principal return value. It that's nil (or 0, or NSNotFound, or NO, or whatever the API defines for that call), _then_ you can examine the error return. Check scriptsFolderURL == nil.
By the way, apparently "error" came in as a parameter. You don't control whether it is NULL, which is legal under the coding standard for return-by-reference NSError. Don't dereference it until you know. I'm surprised that got past the analyzer (unless you assert it's nonnull earlier in the method).
Amend your code and tell us how that affects the bug.
— F
_______________________________________________
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