diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 21:18:25 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 21:18:25 (GMT) |
commit | 6f430e496339aea3e688165340456b555d5e1035 (patch) | |
tree | 197393decf924def07e006f3e35cf21f2fec0f08 /Modules/pyexpat.c | |
parent | dd7c55250d67de4d430a0c51dba4f3c0cd8f6ed3 (diff) | |
download | cpython-6f430e496339aea3e688165340456b555d5e1035.zip cpython-6f430e496339aea3e688165340456b555d5e1035.tar.gz cpython-6f430e496339aea3e688165340456b555d5e1035.tar.bz2 |
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules/pyexpat.c')
-rw-r--r-- | Modules/pyexpat.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index bf81e2a..c965ff4 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1033,13 +1033,16 @@ static PyObject * xmlparse_UseForeignDTD(xmlparseobject *self, PyObject *args) { PyObject *flagobj = NULL; - XML_Bool flag = XML_TRUE; + int flag = 1; enum XML_Error rc; - if (!PyArg_UnpackTuple(args, "UseForeignDTD", 0, 1, &flagobj)) + if (!PyArg_ParseTuple(args, "O:UseForeignDTD", &flagobj)) return NULL; - if (flagobj != NULL) - flag = PyObject_IsTrue(flagobj) ? XML_TRUE : XML_FALSE; - rc = XML_UseForeignDTD(self->itself, flag); + if (flagobj != NULL) { + flag = PyObject_IsTrue(flagobj); + if (flag < 0) + return NULL; + } + rc = XML_UseForeignDTD(self->itself, flag ? XML_TRUE : XML_FALSE); if (rc != XML_ERROR_NONE) { return set_error(self, rc); } @@ -1397,7 +1400,10 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) } assert(PyUnicode_Check(name)); if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) { - if (PyObject_IsTrue(v)) { + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + if (b) { if (self->buffer == NULL) { self->buffer = malloc(self->buffer_size); if (self->buffer == NULL) { @@ -1416,25 +1422,25 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) return 0; } if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) { - if (PyObject_IsTrue(v)) - self->ns_prefixes = 1; - else - self->ns_prefixes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ns_prefixes = b; XML_SetReturnNSTriplet(self->itself, self->ns_prefixes); return 0; } if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->ordered_attributes = 1; - else - self->ordered_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->ordered_attributes = b; return 0; } if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) { - if (PyObject_IsTrue(v)) - self->specified_attributes = 1; - else - self->specified_attributes = 0; + int b = PyObject_IsTrue(v); + if (b < 0) + return -1; + self->specified_attributes = b; return 0; } |