Re: convert password from SecKeychainFindGenericPassword to NSString
Re: convert password from SecKeychainFindGenericPassword to NSString
- Subject: Re: convert password from SecKeychainFindGenericPassword to NSString
- From: Jens Alfke <email@hidden>
- Date: Mon, 1 Feb 2010 08:46:36 -0800
On Feb 1, 2010, at 3:58 AM, Stuart Malin wrote:
> My code worked fine with NSString's +stringWithCString:length: even though the string was not NULL terminated.
Ah, you're right, I'd forgotten that method. It doesn't look for a NUL terminator because the length is given explicitly.
You still shouldn't use it though, because you have no control over the string encoding: it'll use the default encoding for the user's locale. This is MacRoman for English-language users, and various other things for non-English. It's practically guaranteed to give the wrong results on non-ASCII characters. (That's why it's deprecated.)
> When I changed that to +stringWithCString:encoding: I would *sometimes* get incorrect results.
This would happen to work if the next byte past the end of the string were a 0, and would fail (i.e. append random garbage to the string) if it wasn't. In the worst case, it doesn't find a 0 byte before running off the end of allocated address space, and crashes with a bus error. This is a nasty source of random failures and crashes.
—Jens_______________________________________________
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