Trent Mick:

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

Changes by Guido: always accept values [0..255] (in addition to
[CHAR_MIN..CHAR_MAX]) for 'b' format; changed some spaces into tabs in
other code.
This commit is contained in:
Guido van Rossum 2000-05-08 14:02:41 +00:00
parent 07bd90e92d
commit 80dc16baaa
1 changed files with 44 additions and 14 deletions

View File

@ -471,6 +471,16 @@ convertsimple1(arg, p_format, p_va)
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 && ival >= 256) {
PyErr_SetString(PyExc_OverflowError,
"byte integer is greater than maximum");
return "integer<b>";
}
else
*p = (char) ival;
break;
@ -482,6 +492,16 @@ convertsimple1(arg, p_format, p_va)
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 @@ convertsimple1(arg, p_format, p_va)
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;