> On Feb 19, 2016, at 1:17 PM, Jim Adams <jim.ad...@sas.com> 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).

FYI, You must be ignoring compiler warnings, or you've turned off the “type 
check printf” warning setting. Don’t do that ;) I always strongly recommend 
turning on “Treat warnings as errors”, which will force you to fix warnings. 
This is very useful because a number of compiler warnings are actually nasty 
and hard-to-find errors like the above.

—Jens

_______________________________________________

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

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

Reply via email to