discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nasty NSString bug (garbage buffers)


From: Jens Alfke
Subject: Re: Nasty NSString bug (garbage buffers)
Date: Sat, 3 Mar 2012 10:52:40 -0800


On Mar 2, 2012, at 10:29 AM, I wrote:

If you create an NSString object using -initWithBytesNoCopy: — i.e. its backing store points to an app-supplied memory buffer — then new NSStrings created as substrings of it also end up pointing into that same buffer. The effect then is that, even if you’re careful and never use the original string anymore after the buffer contents become invalid, you’ve still got the substrings around, and their contents change into garbage sooner or later when the buffer’s memory gets reused for something else (i.e. very soon thereafter, if the buffer was on the stack.)

I got a couple of off-list replies saying that this behavior is correct/intentional.
In my defense, the code in question runs fine on OS X and iOS, and I’ve written similar code several times in the past, including in apps that have shipped in OS X such as iChat.
But it’s true that the Apple docs don’t say whether or not this is legal. So I’m going to ask around and see if I can get a definitive answer. Also, has anyone looked at what Apple’s open-source CFString implementation does?

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]