]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patches #1298449 and #1298499: Add some missing checks for error
authorMichael W. Hudson <mwh@python.net>
Thu, 22 Sep 2005 09:19:01 +0000 (09:19 +0000)
committerMichael W. Hudson <mwh@python.net>
Thu, 22 Sep 2005 09:19:01 +0000 (09:19 +0000)
returns in cStringIO.c.  Thanks to Andrew Bennetts.

This must be a backport candidate.

Lib/test/test_StringIO.py
Misc/ACKS
Misc/NEWS
Modules/cStringIO.c

index e74a427af0b3bccce95194b84714a7eef9a1ea98..c61f7cc54a3c401dbcac7c224b3eb4ee86beee30 100644 (file)
@@ -44,6 +44,13 @@ class TestGenericStringIO(unittest.TestCase):
         f.seek(0)
         self.assertEqual(f.getvalue(), 'abc')
 
+    def test_writelines_error(self):
+        def errorGen():
+            yield 'a'
+            raise KeyboardInterrupt()
+        f = self.MODULE.StringIO()
+        self.assertRaises(KeyboardInterrupt, f.writelines, errorGen())
+
     def test_truncate(self):
         eq = self.assertEqual
         f = self.MODULE.StringIO()
index bc9ee2b67f0f203fff6c4e4ac72d9af4610fdf3a..c1cb855f239d9217e432d5a83057ff2e395a9058 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -50,6 +50,7 @@ Reimer Behrends
 Thomas Bellman
 Juan M. Bello Rivas
 Alexander Belopolsky
+Andrew Bennetts
 Andy Bensky
 Michel Van den Bergh
 Eric Beser
index 9144f5ddf17331caa104e4164263f1ceb593b4b4..93c2ba0c4952ad5624d2bd96d2cc34a1f772beb2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -149,6 +149,9 @@ present).
 Extension Modules
 -----------------
 
+- Patches #1298449 and #1298499: Add some missing checks for error
+  returns in cStringIO.c.
+
 - Patch #1297028: fix segfault if call type on MultibyteCodec,
   MultibyteStreamReader, or MultibyteStreamWriter
 
index b7333fdd380d458df262c7d852b358e5bff1d2ec..9ed77d82066afa70734a83f31ab9097ece411960 100644 (file)
@@ -241,7 +241,10 @@ IO_readlines(IOobject *self, PyObject *args) {
                line = PyString_FromStringAndSize (output, n);
                if (!line) 
                         goto err;
-               PyList_Append (result, line);
+               if (PyList_Append (result, line) == -1) {
+                       Py_DECREF (line);
+                       goto err;
+               }
                Py_DECREF (line);
                 length += n;
                 if (hint > 0 && length >= hint)
@@ -440,13 +443,18 @@ O_writelines(Oobject *self, PyObject *args) {
                        Py_DECREF(it);
                        Py_DECREF(s);
                        return NULL;
-               }
-               Py_DECREF(s);
-       }
-       Py_DECREF(it);
-       Py_RETURN_NONE;
-}
+               }
+               Py_DECREF(s);
+       }
 
+       Py_DECREF(it);
+
+       /* See if PyIter_Next failed */
+       if (PyErr_Occurred())
+               return NULL;
+
+       Py_RETURN_NONE;
+}
 static struct PyMethodDef O_methods[] = {
   /* Common methods: */
   {"flush",     (PyCFunction)IO_flush,    METH_NOARGS,  IO_flush__doc__},