• 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: NSString vs. unicode encoding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSString vs. unicode encoding


  • Subject: Re: NSString vs. unicode encoding
  • From: Johan Kool <email@hidden>
  • Date: Wed, 16 Sep 2009 11:50:39 -0700


Op 16 sep 2009, om 11:31 heeft Shawn Erickson het volgende geschreven:
On Tue, Sep 15, 2009 at 9:04 PM, Johan Kool <email@hidden> wrote:
Dear list,


I need to work with strings as in stringA. (I don't have much choice, but to have it in a NSString at the start.) I want to have the readable output "hello world".

NSString *stringA = @"hello\040world";
NSString *stringB = [NSString stringWithUTF8String:"hello \040world"] ;


// This works, so I know NSString can deal with the encoding I have in stringA
NSLog(stringB);


// This does not work (as expected)
NSLog([NSString stringWithUTF8String:[stringA UTF8String]]);

// Nor does this work
NSLog([NSString stringWithUTF8String:[[stringA dataUsingEncoding:NSUTF8StringEncoding] bytes]]);


// Or this for that matter
NSLog([NSString stringWithUTF8String:[[stringA dataUsingEncoding:NSASCIIStringEncoding] bytes]]);


Never pass a string like that to NSLog. NSLog takes the first parameter as the FORMAT definition for the log statement. It parses that string looking for %d, etc. and then will attempt pull additional parameters based on what it parses. So it can cause in proper memory/stack access which can crash and/or expose information from you processes memory.

Always ensure the first parameter you pass to NSLog is a proper format string (this goes for any function that takes a format string).

NSLog(@"%@", ...) in this case.

Thanks, you are right. I knew that, this was just a mistake in the code I wrote for phrasing the question. It wasn't (nor solved) the issue I am having unfortunately (see my follow-up post from a few minutes ago).


Johan

---
http://www.johankool.nl/

KOOLISTOV - Software for Mac and iPhone
http://www.koolistov.net/




_______________________________________________

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: 
 >NSString vs. unicode encoding (From: Johan Kool <email@hidden>)
 >Re: NSString vs. unicode encoding (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: Grand Central Dispatch vs CFRunLoop
  • Next by Date: Re: NSToolTipOwner Protocol and Xcode 3.2 build failure in Debug Build Configuration
  • Previous by thread: Re: NSString vs. unicode encoding
  • Next by thread: [JOB] Established iPhone app developer seeks Cocoa Network Engineer
  • Index(es):
    • Date
    • Thread