• 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: Can an NSArray ever have a count of -1?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can an NSArray ever have a count of -1?


  • Subject: Re: Can an NSArray ever have a count of -1?
  • From: Jim Adams <email@hidden>
  • Date: Fri, 19 Feb 2016 22:12:16 +0000
  • Thread-topic: Can an NSArray ever have a count of -1?

It really was the wrong format specifier. Turns out the crash was on the next line where I used %d and %@ together. The -1 was an indicator of the issue but not the cause of my crash.

Thanks for the quick look. I will try that warning flag. I haven’t changed any of those flags so it may very well be warning me.

On Feb 19, 2016, at 4:44 PM, Jean-Daniel Dupas <email@hidden<mailto:email@hidden>> wrote:


Le 19 févr. 2016 à 22:29, Jens Alfke <email@hidden<mailto:email@hidden>> a écrit :


On Feb 19, 2016, at 1:17 PM, Jim Adams <email@hidden<mailto:email@hidden>> wrote:

         SLogInfo(@"Starting csi %ld count %d", csi, sortedEvents.count);

In the console I see:
INFO: Starting csi -1 count -1
The very next line crashes when the sortedEvents are accessed. What could cause the array to have a -1 count?

You’re using the wrong format strings for both of those parameters.

csi is 64-bit so you need %lld. The formatter sees %ld and thinks it’s 32-bit not 64-bit, so it skips the wrong amount of space on the stack when going to the next parameter, which is why you then get a bogus value for the count.

Also, NSArray.count is of type NSUInteger, which is unsigned, and has different sizes on different platforms. The right format specifier is either %lu (in a 32-bit app) or %llu (in 64-bit).

Not exactly. %d is for 32 bit signed integer, but %ld is for signed long, and so is the right formatter for NSInteger value (which is a typedef alias of long) and 64 bit integer on 64 bit platform.

%lld is for signed long long and is the same as long for most platform.

_______________________________________________

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: 
 >Can an NSArray ever have a count of -1? (From: Jim Adams <email@hidden>)
 >Re: Can an NSArray ever have a count of -1? (From: Jens Alfke <email@hidden>)
 >Re: Can an NSArray ever have a count of -1? (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Re: Can an NSArray ever have a count of -1?
  • Next by Date: Re: Can an NSArray ever have a count of -1?
  • Previous by thread: Re: Can an NSArray ever have a count of -1?
  • Next by thread: Re: Can an NSArray ever have a count of -1?
  • Index(es):
    • Date
    • Thread