On Jan 10, 2008 12:41 AM, Duncan Patton a Campbell <[EMAIL PROTECTED]> wrote: > On Wed, 9 Jan 2008 21:51:01 -0700 > "Philip Guenther" <[EMAIL PROTECTED]> wrote: > > > 1) pass the same size value to malloc() and strftime(), and > > Ya, this is it. Needs to be the sizeof the input buffer + 2.
Why? Since the output string should have the same length as the input string, I would expect it to work correctly if you pass both malloc() and strftime() the value strlen(input)+1. > Why this does not [break] in FreeBSD escapes me, tho'. It doesn't appear to break because malloc() is, by happenstance, returning a buffer whose last byte is zero. If that wasn't true, then your code would access beyond the end of a malloced buffer, which has undefined behavior and may cause a SIGSEGV. For example, try running with MALLOC_OPTIONS=J in the environment. Philip Guenther