• 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: cString deprecated!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cString deprecated!


  • Subject: Re: cString deprecated!
  • From: Ali Ozer <email@hidden>
  • Date: Fri, 6 Sep 2002 08:59:25 -0700

This is *very* bad. You *must* check for NULL cause CFRelease has this lame thing where it calls abort or something if you pass it NULL.

Well, it turns out that is not necessary at all here, just like it is not necessary at all in many cases, because the code sequence is already making the assumption cfstring is not NULL. That is, if cfstring is NULL at the time CFRelease is done, the program is already in bad shape, as there was some error in the string creation. If anything, this code sequence should do if (cfstring) check after the creation, as a validation of program logic:

cfstring = CFStringCreateWithCString (NULL, theCString, encoding);
if (cfstring) {
string = [self initWithString:(NSString*)cfstring];
CFRelease (cfstring);
return string; // or [string autorelease] if this is a stringWith... method.
} else {
... handle error case ...
}

If fact, in general --- if you find your program crashes because CFRelease() or any CF function is called with the invalid CF type value of NULL, rather than silencing it with an if(), it's usually a good idea first to look upstream for the reason for the NULL...

Ali
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: cString deprecated!
      • From: Rosyna <email@hidden>
References: 
 >Re: cString deprecated! (From: Rosyna <email@hidden>)

  • Prev by Date: Re: Get parent process (Carbon question)
  • Next by Date: Re: Get parent process (Carbon question)
  • Previous by thread: Re: cString deprecated!
  • Next by thread: Re: cString deprecated!
  • Index(es):
    • Date
    • Thread