Re: sprintf and 64-bit integers

2009-09-15 Thread Sean McBride
On 9/14/09 9:54 PM, Andrew Farmer said: Yes, sprintf is pure evil. snprintf is less evil. Also, I recommend adding -fstack-protector -D_FORTIFY_SOURCE=2, they can help catch some of these problems. And valgrind would probably have caught this problem immediately. Sadly, valgrind hasn't

Re: sprintf and 64-bit integers

2009-09-14 Thread Sean McBride
On 9/13/09 12:01 PM, Jens Alfke said: It would be best to convert all your sprintf calls to snprintf, which is a safer equivalent that won't overflow the buffer. Yes, sprintf is pure evil. snprintf is less evil. Also, I recommend adding -fstack-protector -D_FORTIFY_SOURCE=2, they can help

Re: sprintf and 64-bit integers

2009-09-14 Thread Andrew Farmer
On 14 Sep 2009, at 11:48, Sean McBride wrote: On 9/13/09 12:01 PM, Jens Alfke said: It would be best to convert all your sprintf calls to snprintf, which is a safer equivalent that won't overflow the buffer. Yes, sprintf is pure evil. snprintf is less evil. Also, I recommend adding

sprintf and 64-bit integers

2009-09-13 Thread slasktrattena...@gmail.com
Hi, 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...

Re: sprintf and 64-bit integers

2009-09-13 Thread Bill Bumgarner
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...

Re: sprintf and 64-bit integers

2009-09-13 Thread slasktrattena...@gmail.com
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

Re: sprintf and 64-bit integers

2009-09-13 Thread Steve Christensen
On Sep 13, 2009, at 11:10 AM, slasktrattena...@gmail.com wrote: 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:

Re: sprintf and 64-bit integers

2009-09-13 Thread Clark Cox
On Sun, Sep 13, 2009 at 8:10 PM, slasktrattena...@gmail.com slasktrattena...@gmail.com wrote: 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

Re: sprintf and 64-bit integers

2009-09-13 Thread Greg Guerin
char str[10]; sprintf(str, %d, val); What is the value of val at the time the crash occurs? Will it always convert to 9 digits or less? What value is sprintf() returning? You might want to use snprintf() or asprintf(). -- GG ___ Cocoa-dev

Re: sprintf and 64-bit integers

2009-09-13 Thread slasktrattena...@gmail.com
In this case val was exactly nine digits: 213294334. But it can also be greater sometimes. Sprintf() is returning the same value, using %d on 10.5. On Sun, Sep 13, 2009 at 8:21 PM, Greg Guerin glgue...@amug.org wrote: char str[10]; sprintf(str, %d, val); What is the value of val at the time

Re: sprintf and 64-bit integers

2009-09-13 Thread Greg Guerin
Sprintf() is returning the same value, using %d on 10.5. I meant sprintf()'s returned int value, which is the count of formatted output chars, not including the trailing null. Read 'man sprintf'. Or just try the simple expedient: char str[80]; -- GG

Re: sprintf and 64-bit integers

2009-09-13 Thread Jens Alfke
It would be best to convert all your sprintf calls to snprintf, which is a safer equivalent that won't overflow the buffer. If the value is too long to fit, it'll be truncated instead of overflowing and corrupting the stack. (This type of overflow is one of the main causes of security

Re: sprintf and 64-bit integers

2009-09-13 Thread slasktrattena...@gmail.com
On Sun, Sep 13, 2009 at 8:42 PM, Greg Guerin glgue...@amug.org wrote: Or just try the simple expedient:  char str[80];  -- GG Right, it was a buffer overrun. Simple as that. Thanks guys! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)