From: Serhiy Storchaka Date: Fri, 21 Apr 2017 23:48:11 +0000 (+0300) Subject: bpo-29867: Add asserts in PyTuple_GET_SIZE, PyList_GET_SIZE and PySet_GET_SIZE. ... X-Git-Tag: v3.7.0a1~919 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1a5856bf9295fa73995898d576e0bedf016aee1f;p=thirdparty%2FPython%2Fcpython.git bpo-29867: Add asserts in PyTuple_GET_SIZE, PyList_GET_SIZE and PySet_GET_SIZE. (#751) --- diff --git a/Include/listobject.h b/Include/listobject.h index 31843b5db08c..6057279d51c3 100644 --- a/Include/listobject.h +++ b/Include/listobject.h @@ -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 diff --git a/Include/setobject.h b/Include/setobject.h index 87ec1c8afc00..fc0ea83925f9 100644 --- a/Include/setobject.h +++ b/Include/setobject.h @@ -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; diff --git a/Include/tupleobject.h b/Include/tupleobject.h index c273ce7dc8bd..98c26220ea09 100644 --- a/Include/tupleobject.h +++ b/Include/tupleobject.h @@ -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) diff --git a/Objects/odictobject.c b/Objects/odictobject.c index c2cef21b4977..771dcc308c51 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -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,