[Patches] make 'b','h','i' raise overflow exception (was: issues with int/long on 64bit platforms - eg stringobject (PR#306))

Guido van Rossum guido@python.org
Mon, 08 May 2000 10:00:30 -0400


> Changes the 'b', 'h', and 'i' formatters in PyArg_ParseTuple to raise an
> Overflow exception if they overflow (previously they just silently
> overflowed).

Trent,

There's one issue with this: I believe the 'b' format is mostly used
with unsigned character arguments in practice.  However on systems
with default signed characters, CHAR_MAX is 127 and values 128-255 are
rejected.  I'll change the overflow test to:

	else if (ival > CHAR_MAX && ival >= 256) {

if that's okay with you.

I'm not sure that the same problem arises with the 'h' format, so I'll
leave that one alone.

Another issue however is that there are probably cases where an 'i'
format is used (which can't overflow on 32-bit architectures) but
where the int value is then copied into a short field without an
additional check...  I'm not sure how to fix this except by a complete
inspection of all code...  Not clear if it's worth it.

--Guido van Rossum (home page: http://www.python.org/~guido/)