[Python-Dev] test_builtin failing? or just 64-bit platforms
Fredrik Lundh
fredrik@pythonware.com
Sat, 1 Dec 2001 12:35:16 +0100
Barry A. Warsaw wrote:
> TP> 20 bytes isn't enough to hold the result on a 64-bit box
> TP> (insert rant about the idiot practice of trying to make stack
> TP> buffers as small as possible). You have 20 characters in your
> TP> result, but need 21 to hold the trailing 0 byte too. I don't
> TP> know what snprintf does when there's not enough room, but I
> TP> think you just showed us what it does on Tru64 <wink>.
>
> Heh, I was going to suggest that this might be a good place to
> substitute a call to PyString_FromFormat*() but then I read this
> little nugget:
>
> case 'd': case 'i': case 'x':
> (void) va_arg(count, int);
> /* 20 bytes should be enough to hold a 64-bit
> integer */
> n += 20;
> break;
The size calculated by PyString_FromFormat is used to allocate a
Python string, not a C string. The Python string allocator always
adds an extra 0 byte at the end.
(if it hadn't, I would have used 21 instead)
</F>