[Patches] make 'b','h','i' raise overflow exception (was: issues with int/long on 64bit platforms - eg stringobject (PR#306))
Trent Mick
trentm@activestate.com
Wed, 3 May 2000 16:16:56 -0700
Description:
Changes the 'b', 'h', and 'i' formatters in PyArg_ParseTuple to raise an
Overflow exception if they overflow (previously they just silently
overflowed).
Legal:
I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims"). To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.
I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation. I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.
Patch:
--- main/Apps/Perlium/Python/dist/src/Python/getargs.c.~1~ Tue May 2 16:48:46 2000
+++ main/Apps/Perlium/Python/dist/src/Python/getargs.c Tue May 2 16:48:46
2000
@@ -471,6 +471,16 @@
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<b>";
+ else if (ival < CHAR_MIN) {
+ PyErr_SetString(PyExc_OverflowError,
+ "byte integer is less than minimum");
+ return "integer<b>";
+ }
+ else if (ival > CHAR_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "byte integer is greater than maximum");
+ return "integer<b>";
+ }
else
*p = (char) ival;
break;
@@ -482,6 +492,16 @@
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<h>";
+ else if (ival < SHRT_MIN) {
+ PyErr_SetString(PyExc_OverflowError,
+ "short integer is less than minimum");
+ return "integer<h>";
+ }
+ else if (ival > SHRT_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "short integer is greater than maximum");
+ return "integer<h>";
+ }
else
*p = (short) ival;
break;
@@ -493,6 +513,16 @@
long ival = PyInt_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
return "integer<i>";
+ else if (ival < INT_MIN) {
+ PyErr_SetString(PyExc_OverflowError,
+ "integer is less than minimum");
+ return "integer<i>";
+ }
+ else if (ival > INT_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "integer is greater than maximum");
+ return "integer<i>";
+ }
else
*p = ival;
break;
End of Patch.