Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with NSString, UTF8, pathnames




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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.