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 protected]<mailto:[email protected]>> wrote:


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


On Feb 19, 2016, at 1:17 PM, Jim Adams 
<[email protected]<mailto:[email protected]>> 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 protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to