summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-08-15 21:16:51 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-08-15 21:16:51 (GMT)
commitc5bef75c77af414c2f6c5901b6838d3071313bc7 (patch)
treeec54e539c09e4c9b6fc8963258fef4c6484e5573 /Modules
parent4ffe9a064022b973ab152d108b13c470af486a74 (diff)
downloadcpython-c5bef75c77af414c2f6c5901b6838d3071313bc7.zip
cpython-c5bef75c77af414c2f6c5901b6838d3071313bc7.tar.gz
cpython-c5bef75c77af414c2f6c5901b6838d3071313bc7.tar.bz2
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_csv.c8
-rw-r--r--Modules/_io/textio.c5
-rw-r--r--Modules/_ssl.c6
-rw-r--r--Modules/cStringIO.c6
-rw-r--r--Modules/itertoolsmodule.c17
-rw-r--r--Modules/parsermodule.c18
-rw-r--r--Modules/pyexpat.c54
7 files changed, 75 insertions, 39 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index ea3add2..ab2a5ed 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -208,8 +208,12 @@ _set_bool(const char *name, int *target, PyObject *src, int dflt)
{
if (src == NULL)
*target = dflt;
- else
- *target = PyObject_IsTrue(src);
+ else {
+ int b = PyObject_IsTrue(src);
+ if (b < 0)
+ return -1;
+ *target = b;
+ }
return 0;
}
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 2662e4b..1746604 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1013,8 +1013,11 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
res = PyObject_CallMethod(buffer, "seekable", NULL);
if (res == NULL)
goto error;
- self->seekable = self->telling = PyObject_IsTrue(res);
+ r = PyObject_IsTrue(res);
Py_DECREF(res);
+ if (r < 0)
+ goto error;
+ self->seekable = self->telling = r;
self->encoding_start_of_stream = 0;
if (self->seekable && self->encoder) {
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index e692b5d..195e5b6 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1005,6 +1005,7 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
int len;
int verification;
PyObject *binary_mode = Py_None;
+ int b;
if (!PyArg_ParseTuple(args, "|O:peer_certificate", &binary_mode))
return NULL;
@@ -1012,7 +1013,10 @@ PySSL_peercert(PySSLObject *self, PyObject *args)
if (!self->peer_cert)
Py_RETURN_NONE;
- if (PyObject_IsTrue(binary_mode)) {
+ b = PyObject_IsTrue(binary_mode);
+ if (b < 0)
+ return NULL;
+ if (b) {
/* return cert in DER-encoded format */
unsigned char *bytes_buf = NULL;
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 89f1dd6..a19a31e 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -127,12 +127,16 @@ IO_cgetval(PyObject *self) {
static PyObject *
IO_getval(IOobject *self, PyObject *args) {
PyObject *use_pos=Py_None;
+ int b;
Py_ssize_t s;
if (!IO__opencheck(self)) return NULL;
if (!PyArg_UnpackTuple(args,"getval", 0, 1,&use_pos)) return NULL;
- if (PyObject_IsTrue(use_pos)) {
+ b = PyObject_IsTrue(use_pos);
+ if (b < 0)
+ return NULL;
+ if (b) {
s=self->pos;
if (s > self->string_size) s=self->string_size;
}
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index b51ccf9..f6d0e23 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -903,11 +903,13 @@ dropwhile_next(dropwhileobject *lz)
}
ok = PyObject_IsTrue(good);
Py_DECREF(good);
- if (!ok) {
+ if (ok == 0) {
lz->start = 1;
return item;
}
Py_DECREF(item);
+ if (ok < 0)
+ return NULL;
}
}
@@ -1043,10 +1045,11 @@ takewhile_next(takewhileobject *lz)
}
ok = PyObject_IsTrue(good);
Py_DECREF(good);
- if (ok)
+ if (ok > 0)
return item;
Py_DECREF(item);
- lz->stop = 1;
+ if (ok == 0)
+ lz->stop = 1;
return NULL;
}
@@ -3001,9 +3004,11 @@ ifilter_next(ifilterobject *lz)
ok = PyObject_IsTrue(good);
Py_DECREF(good);
}
- if (ok)
+ if (ok > 0)
return item;
Py_DECREF(item);
+ if (ok < 0)
+ return NULL;
}
}
@@ -3144,9 +3149,11 @@ ifilterfalse_next(ifilterfalseobject *lz)
ok = PyObject_IsTrue(good);
Py_DECREF(good);
}
- if (!ok)
+ if (ok == 0)
return item;
Py_DECREF(item);
+ if (ok < 0)
+ return NULL;
}
}
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 462cb74..8e581c2 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -350,10 +350,14 @@ parser_st2tuple(PyST_Object *self, PyObject *args, PyObject *kw)
int lineno = 0;
int col_offset = 0;
if (line_option != NULL) {
- lineno = (PyObject_IsTrue(line_option) != 0) ? 1 : 0;
+ lineno = PyObject_IsTrue(line_option);
+ if (lineno < 0)
+ return NULL;
}
if (col_option != NULL) {
- col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0;
+ col_offset = PyObject_IsTrue(col_option);
+ if (col_offset < 0)
+ return NULL;
}
/*
* Convert ST into a tuple representation. Use Guido's function,
@@ -401,10 +405,14 @@ parser_st2list(PyST_Object *self, PyObject *args, PyObject *kw)
int lineno = 0;
int col_offset = 0;
if (line_option != 0) {
- lineno = PyObject_IsTrue(line_option) ? 1 : 0;
+ lineno = PyObject_IsTrue(line_option);
+ if (lineno < 0)
+ return NULL;
}
- if (col_option != NULL) {
- col_offset = (PyObject_IsTrue(col_option) != 0) ? 1 : 0;
+ if (col_option != 0) {
+ col_offset = PyObject_IsTrue(col_option);
+ if (col_offset < 0)
+ return NULL;
}
/*
* Convert ST into a tuple representation. Use Guido's function,
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 976908c..4d9a1e5 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1174,13 +1174,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);
}
@@ -1549,7 +1552,10 @@ xmlparse_setattr(xmlparseobject *self, char *name, PyObject *v)
return -1;
}
if (strcmp(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) {
@@ -1568,39 +1574,39 @@ xmlparse_setattr(xmlparseobject *self, char *name, PyObject *v)
return 0;
}
if (strcmp(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 (strcmp(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 (strcmp(name, "returns_unicode") == 0) {
- if (PyObject_IsTrue(v)) {
+ int b = PyObject_IsTrue(v);
+ if (b < 0)
+ return -1;
#ifndef Py_USING_UNICODE
+ if (b) {
PyErr_SetString(PyExc_ValueError,
"Unicode support not available");
return -1;
-#else
- self->returns_unicode = 1;
-#endif
}
- else
- self->returns_unicode = 0;
+#endif
+ self->returns_unicode = b;
return 0;
}
if (strcmp(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;
}