On Sun, Sep 13, 2009 at 8:01 PM, Bill Bumgarner <b...@mac.com> wrote: > On Sep 13, 2009, at 10:59 AM, slasktrattena...@gmail.com wrote: > I'm updating my code for Snow Leopard and ran into this problem. The >> >> app crashes at this line: >> >> sprintf(str, "%d", val); >> >> where val is a CFIndex. According to the string programming guide here... >> >> >> http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html >> >> ...I need to cast my CFIndex to long and replace the %d format >> specifier to %ld. I tried that but still got the crash. So I kept >> trying with all the format specifiers in the book, declaring my >> variable a NSInteger, unsigned int, etc, but no matter what the app >> kept crashing. The only that that actually worked was %lx, but then I >> get the numbers all wrong. It seems that sprintf only accepts 32-bit >> integers. Is this correct? If so, what's the workaround? I'm compiling >> for both 10.5 and 10.6. Advice appreciated, thanks. > > You are off in the weeds. > > There is nothing about a value conversion that could cause a crash. Wrong > value? Sure. But not a crash. Thus, the formatting string is *not* causing > a crash. > > The problem is almost assuredly that 'str' is pointing to garbage, > uninitialized or otherwise wrong. > > Post the code for how str is created. > > b.bum
Sorry, str is simply created like this: char str[10]; sprintf(str, "%d", val); _______________________________________________ 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