diff Lib/test/test_bytes.py @ 58389:fb337cb46b9d 3.1

Merged revisions 77576 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77576 | antoine.pitrou | 2010-01-17 13:38:54 +0100 (dim., 17 janv. 2010) | 12 lines Merged revisions 77573 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77573 | antoine.pitrou | 2010-01-17 13:26:20 +0100 (dim., 17 janv. 2010) | 6 lines Issue #7561: Operations on empty bytearrays (such as `int(bytearray())`) could crash in many places because of the PyByteArray_AS_STRING() macro returning NULL. The macro now returns a statically allocated empty string instead. ........ ................
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 17 Jan 2010 12:43:00 +0000
parents b0e4efb83d60
children 6de64896c6f8
line wrap: on
line diff
--- a/Lib/test/test_bytes.py	Sun Jan 17 12:19:45 2010 +0000
+++ b/Lib/test/test_bytes.py	Sun Jan 17 12:43:00 2010 +0000
@@ -811,6 +811,14 @@
         self.assertRaises(BufferError, delslice)
         self.assertEquals(b, orig)
 
+    def test_empty_bytearray(self):
+        # Issue #7561: operations on empty bytearrays could crash in many
+        # situations, due to a fragile implementation of the
+        # PyByteArray_AS_STRING() C macro.
+        self.assertRaises(ValueError, int, bytearray(b''))
+        self.assertRaises((ValueError, OSError), os.mkdir, bytearray(b''))
+
+
 class AssortedBytesTest(unittest.TestCase):
     #
     # Test various combinations of bytes and bytearray