Re: problem with NSString, UTF8, pathnames
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