On 6 Feb 2009, at 06:32, Martin Wierschin wrote:

On Feb 5, 2009, at 4:42 PM, Steve Sisak wrote:

NSString * newString = [inputString stringByReplacingCharactersInRange:range withString:@""];
        [inputString release]; // release old inputString
        inputString = [newString retain]; // retain new inputString

This sequence is not safe. As an optimization there is nothing preventing "inputString" from returning self if "range" is of zero length. If that ever happened, you could end up deallocating the string before the following retain occurs.

So retain newString before releasing inputString - or explicitly test for pointer equality and only do the release and retain if they are not equal.

NSString * newString = [[inputString stringByReplacingCharactersInRange:range withString:@""] retain];
        [inputString release]; // release old inputString
        inputString = newString ;



As has been suggested, using a single mutable string is probably the best way to go.

Agreed



~Martin
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/adc%40jeremyp.net

This email sent to a...@jeremyp.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to