]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fixed problem with missing PyInt_CheckExact() macro in _ctypes.c
authorChristian Heimes <christian@cheimes.de>
Wed, 5 Dec 2007 09:33:00 +0000 (09:33 +0000)
committerChristian Heimes <christian@cheimes.de>
Wed, 5 Dec 2007 09:33:00 +0000 (09:33 +0000)
Modules/_ctypes/_ctypes.c

index 00643ac9a758943e6ebd1068a1752fb2933cecf9..54e79638137e2d16411a48093e0fc5c09713db83 100644 (file)
@@ -954,8 +954,8 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
        StgDictObject *itemdict;
        PyObject *proto;
        PyObject *typedict;
-       int length;
-
+       long length;
+       int overflow;
        Py_ssize_t itemsize, itemalign;
 
        typedict = PyTuple_GetItem(args, 2);
@@ -963,13 +963,18 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                return NULL;
 
        proto = PyDict_GetItemString(typedict, "_length_"); /* Borrowed ref */
-       if (!proto || !PyInt_CheckExact(proto)) {
+       if (!proto || !PyLong_Check(proto)) {
                PyErr_SetString(PyExc_AttributeError,
                                "class must define a '_length_' attribute, "
                                "which must be a positive integer");
                return NULL;
        }
-       length = PyLong_AS_LONG(proto);
+       length = PyLong_AsLongAndOverflow(proto, &overflow);
+       if (overflow) {
+               PyErr_SetString(PyExc_OverflowError,
+                               "The '_length_' attribute is too large");
+               return NULL;
+       }
 
        proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
        if (!proto) {