summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-07 23:29:20 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-07 23:29:20 (GMT)
commit75c26bc6a78169bf621885fa91b0d8f93241e682 (patch)
treec7d2ca9081ef06f7cb0edbc687fc780e3a385300
parenta05577059d6ed67f69e9384252647e2232315f2f (diff)
downloadcpython-75c26bc6a78169bf621885fa91b0d8f93241e682.zip
cpython-75c26bc6a78169bf621885fa91b0d8f93241e682.tar.gz
cpython-75c26bc6a78169bf621885fa91b0d8f93241e682.tar.bz2
BZ2File.read(0) should return b"" rather than raising ValueError.
This fixes test_tarfile.py. I've added a unit test for the correct bz2 behavior.
-rw-r--r--Lib/test/test_bz2.py8
-rw-r--r--Modules/bz2module.c2
2 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index 28af42e..06293f5 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -65,6 +65,14 @@ class BZ2FileTest(BaseTest):
self.assertEqual(bz2f.read(), self.TEXT)
bz2f.close()
+ def testRead0(self):
+ # Test BBZ2File.read(0)"
+ self.createTempFile()
+ bz2f = BZ2File(self.filename)
+ self.assertRaises(TypeError, bz2f.read, None)
+ self.assertEqual(bz2f.read(0), b"")
+ bz2f.close()
+
def testReadChunk10(self):
# "Test BZ2File.read() in chunks of 10 bytes"
self.createTempFile()
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index ee2186e..954c914 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -431,7 +431,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
goto cleanup;
}
ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
- if (ret == NULL)
+ if (ret == NULL || buffersize == 0)
goto cleanup;
bytesread = 0;