summaryrefslogtreecommitdiff
path: root/Modules/bz2module.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-08-14 21:42:55 +0000
committerGeorg Brandl <georg@python.org>2006-08-14 21:42:55 +0000
commit3335a7ad63092d232098fec292cf9b3a25c66a83 (patch)
treef2295faf6d6fb32d537ca1e94237ecd1d3dabbce /Modules/bz2module.c
parent2463f8f831bdf7ed562a26a13a6214f203f0b037 (diff)
downloadcpython-git-3335a7ad63092d232098fec292cf9b3a25c66a83.tar.gz
Patch #1535500: fix segfault in BZ2File.writelines and make sure it
raises the correct exceptions.
Diffstat (limited to 'Modules/bz2module.c')
-rw-r--r--Modules/bz2module.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index 5e5a801907..24b2489151 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -812,12 +812,12 @@ BZ2File_write(BZ2FileObject *self, PyObject *args)
case MODE_CLOSED:
PyErr_SetString(PyExc_ValueError,
"I/O operation on closed file");
- goto cleanup;;
+ goto cleanup;
default:
PyErr_SetString(PyExc_IOError,
"file is not ready for writing");
- goto cleanup;;
+ goto cleanup;
}
self->f_softspace = 0;
@@ -861,6 +861,21 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
int bzerror;
ACQUIRE_LOCK(self);
+ switch (self->mode) {
+ case MODE_WRITE:
+ break;
+
+ case MODE_CLOSED:
+ PyErr_SetString(PyExc_ValueError,
+ "I/O operation on closed file");
+ goto error;
+
+ default:
+ PyErr_SetString(PyExc_IOError,
+ "file is not ready for writing");
+ goto error;
+ }
+
islist = PyList_Check(seq);
if (!islist) {
iter = PyObject_GetIter(seq);