summaryrefslogtreecommitdiffstats
path: root/Objects/structseq.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2002-12-18 23:20:39 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2002-12-18 23:20:39 (GMT)
commit8feeabb975f416a8cc8bc44d466982da44cf0f54 (patch)
tree5d3c3d1761ee040ebc8c2f52da8d1a4102dc1e1f /Objects/structseq.c
parent543c9253cd19ae99c218c5b5e9d5b8dd49e2468e (diff)
downloadcpython-8feeabb975f416a8cc8bc44d466982da44cf0f54.zip
cpython-8feeabb975f416a8cc8bc44d466982da44cf0f54.tar.gz
cpython-8feeabb975f416a8cc8bc44d466982da44cf0f54.tar.bz2
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.
Diffstat (limited to 'Objects/structseq.c')
-rw-r--r--Objects/structseq.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/structseq.c b/Objects/structseq.c
index e14e4ca..effe360 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -150,6 +150,9 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
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 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
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 @@ PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
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);
}