Mercurial > cpython-lru_cache-weakref
diff Objects/structseq.c @ 26708:3593f2b91d7d legacy-trunk
SF # 654974, fix unchecked return values in structseq
Check return values after memory allocation.
Also use Py_True instead of PyInt_FromLong(1) for bool value.
Backport candidate.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Wed, 18 Dec 2002 23:20:39 +0000 |
| parents | fdca87c4234e |
| children | 674f3eecffc5 |
line wrap: on
line diff
--- a/Objects/structseq.c Wed Dec 18 23:17:26 2002 +0000 +++ b/Objects/structseq.c Wed Dec 18 23:20:39 2002 +0000 @@ -150,6 +150,9 @@ } res = (PyStructSequence*) PyStructSequence_New(type); + if (res == NULL) { + return NULL; + } for (i = 0; i < len; ++i) { PyObject *v = PySequence_Fast_GET_ITEM(arg, i); Py_INCREF(v); @@ -360,6 +363,8 @@ type->tp_itemsize = 0; members = PyMem_NEW(PyMemberDef, n_members-n_unnamed_members+1); + if (members == NULL) + return; for (i = k = 0; i < n_members; ++i) { if (desc->fields[i].name == PyStructSequence_UnnamedField) @@ -387,6 +392,5 @@ PyInt_FromLong((long) n_members)); PyDict_SetItemString(dict, unnamed_fields_key, PyInt_FromLong((long) n_unnamed_members)); - PyDict_SetItemString(dict, "__safe_for_unpickling__", - PyInt_FromLong(1)); + PyDict_SetItemString(dict, "__safe_for_unpickling__", Py_True); }
