bpo-29867: Add asserts in PyTuple_GET_SIZE, PyList_GET_SIZE and PySet_GET_SIZE. ...
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 21 Apr 2017 23:48:11 +0000 (02:48 +0300)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 21 Apr 2017 23:48:11 +0000 (01:48 +0200)
Include/listobject.h
Include/setobject.h
Include/tupleobject.h
Objects/odictobject.c

index 31843b5db08c1ac0563ac40b7d4964d3b3aeb63c..6057279d51c3a482510e0a69ad7f99103344fe8c 100644 (file)
@@ -71,7 +71,7 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
 #ifndef Py_LIMITED_API
 #define PyList_GET_ITEM(op, i) (((PyListObject *)(op))->ob_item[i])
 #define PyList_SET_ITEM(op, i, v) (((PyListObject *)(op))->ob_item[i] = (v))
-#define PyList_GET_SIZE(op)    Py_SIZE(op)
+#define PyList_GET_SIZE(op)    (assert(PyList_Check(op)),Py_SIZE(op))
 #define _PyList_ITEMS(op)      (((PyListObject *)(op))->ob_item)
 #endif
 
index 87ec1c8afc00c4b8262f5327f735960c1c1d939b..fc0ea83925f92f2e51a6f61a1e8060ee928f5865 100644 (file)
@@ -64,7 +64,7 @@ typedef struct {
     PyObject *weakreflist;      /* List of weak references */
 } PySetObject;
 
-#define PySet_GET_SIZE(so) (((PySetObject *)(so))->used)
+#define PySet_GET_SIZE(so) (assert(PyAnySet_Check(so)),(((PySetObject *)(so))->used))
 
 PyAPI_DATA(PyObject *) _PySet_Dummy;
 
index c273ce7dc8bd86f767dc5cb5b54180787087ec26..98c26220ea09ba5e203b951bb9ce9044cb2691a6 100644 (file)
@@ -56,7 +56,7 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
 /* Macro, trading safety for speed */
 #ifndef Py_LIMITED_API
 #define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
-#define PyTuple_GET_SIZE(op)    Py_SIZE(op)
+#define PyTuple_GET_SIZE(op)    (assert(PyTuple_Check(op)),Py_SIZE(op))
 
 /* Macro, *only* to be used to fill in brand new tuples */
 #define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
index c2cef21b49774856447d66611961c009188d1f12..771dcc308c51a824e81e8ec2abc5cfdbf1d11e2d 100644 (file)
@@ -1519,7 +1519,7 @@ odict_repr(PyODictObject *self)
             count++;
         }
         if (count < PyList_GET_SIZE(pieces))
-            PyList_GET_SIZE(pieces) = count;
+            Py_SIZE(pieces) = count;
     }
     else {
         PyObject *items = _PyObject_CallMethodIdObjArgs((PyObject *)self,