mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
Forward-port of r52136,52138: a review of overflow-detecting code.
* unified the way intobject, longobject and mystrtoul handle values around -sys.maxint-1. * in general, trying to entierely avoid overflows in any computation involving signed ints or longs is extremely involved. Fixed a few simple cases where a compiler might be too clever (but that's all guesswork). * more overflow checks against bad data in marshal.c. * 2.5 specific: fixed a number of places that were still confusing int and Py_ssize_t. Some of them could potentially have caused "real-world" breakage. * list.pop(x): fixing overflow issues on x was messy. I just reverted to PyArg_ParseTuple("n"), which does the right thing. (An obscure test was trying to give a Decimal to list.pop()... doesn't make sense any more IMHO) * trying to write a few tests...
This commit is contained in:
parent
0d2f498a4c
commit
7ccbca93a2
19 changed files with 186 additions and 106 deletions
|
@ -863,17 +863,12 @@ static PyObject *
|
|||
listpop(PyListObject *self, PyObject *args)
|
||||
{
|
||||
Py_ssize_t i = -1;
|
||||
PyObject *v, *arg = NULL;
|
||||
PyObject *v;
|
||||
int status;
|
||||
|
||||
if (!PyArg_UnpackTuple(args, "pop", 0, 1, &arg))
|
||||
if (!PyArg_ParseTuple(args, "|n:pop", &i))
|
||||
return NULL;
|
||||
if (arg != NULL) {
|
||||
if (PyInt_Check(arg))
|
||||
i = PyInt_AS_LONG((PyIntObject*) arg);
|
||||
else if (!PyArg_ParseTuple(args, "|n:pop", &i))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->ob_size == 0) {
|
||||
/* Special-case most common failure cause */
|
||||
PyErr_SetString(PyExc_IndexError, "pop from empty list");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue