summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-04-04 21:57:12 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-04-04 21:57:12 (GMT)
commitb2064d72804ffd4c3877420439589c8a0b700af2 (patch)
treefea0c7b0dda8f5dfc4e585c5a99bd74a51173208
parent3608f0570e634ac127ed9bce10d305d16a19e984 (diff)
downloadcpython-b2064d72804ffd4c3877420439589c8a0b700af2.zip
cpython-b2064d72804ffd4c3877420439589c8a0b700af2.tar.gz
cpython-b2064d72804ffd4c3877420439589c8a0b700af2.tar.bz2
Fix-up error-exits on struct_unpack().
-rw-r--r--Modules/_struct.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index ba276b3..328acd9 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1487,29 +1487,33 @@ s_unpack(PyObject *self, PyObject *inputstr)
{
char *start;
int len;
- PyObject * args;
+ PyObject *args=NULL, *result;
PyStructObject *soself = (PyStructObject *)self;
assert(PyStruct_Check(self));
assert(soself->s_codes != NULL);
- if (inputstr != NULL && PyString_Check(inputstr) &&
+ if (inputstr == NULL)
+ goto fail;
+ if (PyString_Check(inputstr) &&
PyString_GET_SIZE(inputstr) == soself->s_size) {
return s_unpack_internal(soself, PyString_AS_STRING(inputstr));
}
args = PyTuple_Pack(1, inputstr);
if (args == NULL)
return NULL;
- if (!PyArg_ParseTuple(args, "s#:unpack", &start, &len)) {
- Py_DECREF(args);
- return NULL;
- }
+ if (!PyArg_ParseTuple(args, "s#:unpack", &start, &len))
+ goto fail;
+ if (soself->s_size != len)
+ goto fail;
+ result = s_unpack_internal(soself, start);
Py_DECREF(args);
- if (soself->s_size != len) {
- PyErr_Format(StructError,
- "unpack requires a string argument of length %zd",
- soself->s_size);
- return NULL;
- }
- return s_unpack_internal(soself, start);
+ return result;
+
+fail:
+ Py_XDECREF(args);
+ PyErr_Format(StructError,
+ "unpack requires a string argument of length %zd",
+ soself->s_size);
+ return NULL;
}
PyDoc_STRVAR(s_unpack_from__doc__,