From 978809518d823c6f67ed7be2563de52275ea8623 Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Thu, 5 Oct 2006 18:37:08 +0000 Subject: [Partial backport of r51218 | neal.norwitz -- the changes to ast.c, symtable.c, and _elementtree.c weren't applicable] Klocwork made another run and found a bunch more problems. This is the first batch of fixes that should be easy to verify based on context. This fixes problem numbers: 220 (ast), 323-324 (symtable), 321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree). --- Modules/_codecsmodule.c | 3 ++- Modules/arraymodule.c | 4 ++++ Objects/structseq.c | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index 3441f61..eef63a7 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -226,7 +226,8 @@ escape_encode(PyObject *self, buf = PyString_AS_STRING (str); len = PyString_GET_SIZE (str); memmove(buf, buf+1, len-2); - _PyString_Resize(&str, len-2); + if (_PyString_Resize(&str, len-2) < 0) + return NULL; return codec_tuple(str, PyString_Size(str)); } diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 593fc48..d8b1eaa 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -701,6 +701,8 @@ array_ass_slice(arrayobject *a, int ilow, int ihigh, PyObject *v) /* Special case "a[i:j] = a" -- copy b first */ int ret; v = array_slice(b, 0, n); + if (!v) + return -1; ret = array_ass_slice(a, ilow, ihigh, v); Py_DECREF(v); return ret; @@ -1687,6 +1689,8 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value) if (self == av) { value = array_slice(av, 0, av->ob_size); av = (arrayobject*)value; + if (!av) + return -1; } else { Py_INCREF(value); diff --git a/Objects/structseq.c b/Objects/structseq.c index 603477f..d0476f6 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -215,6 +215,8 @@ structseq_contains(PyStructSequence *obj, PyObject *o) PyObject *tup; int result; tup = make_tuple(obj); + if (!tup) + return -1; result = PySequence_Contains(tup, o); Py_DECREF(tup); return result; @@ -226,6 +228,8 @@ structseq_hash(PyObject *obj) PyObject *tup; long result; tup = make_tuple((PyStructSequence*) obj); + if (!tup) + return -1; result = PyObject_Hash(tup); Py_DECREF(tup); return result; -- cgit v0.12