]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport r67975: #4759: fix segfault in bytearray.translate(x, None).
authorGeorg Brandl <georg@python.org>
Sun, 28 Dec 2008 11:55:24 +0000 (11:55 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 28 Dec 2008 11:55:24 +0000 (11:55 +0000)
Lib/test/test_bytes.py
Misc/NEWS
Objects/bytearrayobject.c

index 36defb8a846e6c855d2b8b09f8fe3edaf41369bd..00aee028b18d49a1cc863865f55ba1b82855adb7 100644 (file)
@@ -872,11 +872,19 @@ class AssortedBytesTest(unittest.TestCase):
 
     def test_translate(self):
         b = b'hello'
+        ba = bytearray(b)
         rosetta = bytearray(range(0, 256))
         rosetta[ord('o')] = ord('e')
         c = b.translate(rosetta, b'l')
         self.assertEqual(b, b'hello')
         self.assertEqual(c, b'hee')
+        c = ba.translate(rosetta, b'l')
+        self.assertEqual(ba, b'hello')
+        self.assertEqual(c, b'hee')
+        c = b.translate(None, b'e')
+        self.assertEqual(c, b'hllo')
+        self.assertRaises(TypeError, b.translate, b'a'*256, None)
+        self.assertRaises(TypeError, ba.translate, b'a'*256, None)
 
     def test_split_bytearray(self):
         self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])
index b75ddf9034c21270117c48652c239a2f3dcd3161..3bea977e706c42e4117b90b01955c0162ef3a4bc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6.2
 Core and Builtins
 -----------------
 
+- Issue #4759: fix a segfault for bytearray.translate(x, None).
+
 - Added test case to ensure attempts to read from a file opened for writing
   fail.
 
index d75eb53e437c4027af008719e339851af62f2cbc..56071a0cce18317eac712f617eda6ce03cc5e776 100644 (file)
@@ -1465,6 +1465,7 @@ bytes_translate(PyByteArrayObject *self, PyObject *args)
     if (delobj != NULL) {
         if (_getbuffer(delobj, &vdel) < 0) {
             result = NULL;
+            delobj = NULL;  /* don't try to release vdel buffer on exit */
             goto done;
         }
     }