• 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: problem with NSString, UTF8, pathnames
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with NSString, UTF8, pathnames


  • Subject: Re: problem with NSString, UTF8, pathnames
  • From: glenn andreas <email@hidden>
  • Date: Thu, 25 Oct 2007 12:53:20 -0500


On Oct 25, 2007, at 12:46 PM, James Stein wrote:

To my surprise:
an NSString returned by Cocoa will cause NSLog to crash.
Details:

I override 'openDocumentWithContentsOfURL:display:error'
in order to see what is happening.
The NSURL (absoluteURL) passed in comes from Cocoa's normal open file dialog.
so:
NSString *s = [absoluteURL description]; // make NSString from NSURL
NSLog(s); // often works, sometimes crashes.



Never, ever, pass an arbitrary NSString as the first parameter of NSLog - that parameter is suppose to be the _format_of the data, not the data itself.


Any "%" in the string will cause NSLog to start looking for parameters on the stack (and there won't be any), which will cause garbage or crash.

You should instead do:

NSLog(@"%@", s);




Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures, fractals, art



_______________________________________________

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


References: 
 >problem with NSString, UTF8, pathnames (From: "James Stein" <email@hidden>)

  • Prev by Date: Re: Any caveats to using fork in a Foundation/CoreFoundation tool?
  • Next by Date: Re: problem with NSString, UTF8, pathnames
  • Previous by thread: problem with NSString, UTF8, pathnames
  • Next by thread: Re: problem with NSString, UTF8, pathnames
  • Index(es):
    • Date
    • Thread