• 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
Mystifying index out of bounds error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mystifying index out of bounds error


  • Subject: Mystifying index out of bounds error
  • From: Antonio Nunes <email@hidden>
  • Date: Thu, 01 Nov 2012 13:11:16 +0100

Hi,

I have this code in my app:

- (void)keyDown:(NSEvent *)theEvent
{
	unichar		oneChar;
	NSString	*theChars = [theEvent charactersIgnoringModifiers];

	if ( 0 == theChars.length ) {
		return;
	}

	oneChar = [theChars characterAtIndex:0];

	…
}

After about 10 months of the app being available, with this method unchanged, I received a single crash report that points to a crash on the last line:
-[__NSCFConstantString characterAtIndex:]: Range or index out of bounds


The length property of a string returns an NSUInteger, so it should never be lower than zero. I don't see how the out of bounds error could ever happen for index 0, when the string has a length greater than 0. Any ideas? (Considering that I only ever received a single report for what is an often exercised bit of code, should I just consider this a freak incident and ignore it?)

-António

-----------------------------------------------------------
Don't believe everything you think
-----------------------------------------------------------


_______________________________________________

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


  • Follow-Ups:
    • Re: Mystifying index out of bounds error
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Extremely low fps during transparent NSWindow resize
  • Next by Date: Re: WebPolicyDelegate declared where?
  • Previous by thread: Re: Extremely low fps during transparent NSWindow resize
  • Next by thread: Re: Mystifying index out of bounds error
  • Index(es):
    • Date
    • Thread