[Python-checkins] r42504 - python/trunk/Python/getargs.c

"Martin v. Löwis" martin at v.loewis.de
Mon Feb 20 02:01:31 CET 2006


Neal Norwitz wrote:
> Won't work in what sense?
> 
> I don't think there was a bug in the code, beyond the warning.

There certainly was a bug in the code. It was passing a Py_ssize_t,
yet printing an int. I keep forgetting the precise rules for
varargs, but I *think* the varargs recipient is supposed to specify
the correct type always, where "correct" could mean "after possible
widening of the actual parameter to int". So a bad printf parameter
passing could actually crash.

Now, with the cast, you have introduced a possible (silent) truncation
of Py_ssize_t to long. If it could ever happen that the value is out
of range for long, you would lose information. This can't happen,
because we are limited to 2**31 or so actual parameters in a
CALL_FUNCTION, but it isn't at all obvious that, because of that
limitation, the cast will never lose data.

Regards,
Martin


More information about the Python-checkins mailing list