[Python-Dev] test_builtin failing? or just 64-bit platforms (original) (raw)

Barry A. Warsaw barry@zope.com
Fri, 30 Nov 2001 23:17:31 -0500


"TP" == Tim Peters <tim.one@home.com> writes:

TP> It doesn't make sense, but it *smells* like a sprintf ->
TP> PyOS_snprintf screwup ... OK, our int repr code has always
TP> been wrong(!):

| static PyObject *
| int_repr(PyIntObject *v)
| {
| 	char buf[20];
| 	PyOS_snprintf(buf, sizeof(buf), "%ld", v->ob_ival);
| 	return PyString_FromString(buf);
| }

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;

love-ly y'rs, -Barry