summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-04-19 17:03:52 (GMT)
committerGitHub <noreply@github.com>2017-04-19 17:03:52 (GMT)
commitbf623ae8843dc30b28c574bec8d29fc14be59d86 (patch)
tree0a7ab5b441e0306767bfbc6da4522e4af34ab9e6 /Modules/_io
parentc209b70d610da50a844a3c10f37d6183bade3446 (diff)
downloadcpython-bf623ae8843dc30b28c574bec8d29fc14be59d86.zip
cpython-bf623ae8843dc30b28c574bec8d29fc14be59d86.tar.gz
cpython-bf623ae8843dc30b28c574bec8d29fc14be59d86.tar.bz2
bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (#1096)
raised an error. Replace them with using concrete types API that never fails if appropriate.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/iobase.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index b7a506b..bcefb38 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -618,7 +618,8 @@ iobase_iternext(PyObject *self)
if (line == NULL)
return NULL;
- if (PyObject_Size(line) == 0) {
+ if (PyObject_Size(line) <= 0) {
+ /* Error or empty */
Py_DECREF(line);
return NULL;
}
@@ -670,6 +671,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
}
while (1) {
+ Py_ssize_t line_length;
PyObject *line = PyIter_Next(it);
if (line == NULL) {
if (PyErr_Occurred()) {
@@ -683,11 +685,14 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
Py_DECREF(line);
goto error;
}
- length += PyObject_Size(line);
+ line_length = PyObject_Size(line);
Py_DECREF(line);
-
- if (length > hint)
+ if (line_length < 0) {
+ goto error;
+ }
+ if (line_length > hint - length)
break;
+ length += line_length;
}
Py_DECREF(it);