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

index b1427b586edb9036f452beb3e654aefbce8a5d22..b75f62577779f9fb01bb3ca8ec1c5cb6db0a23a5 100644 (file)
@@ -888,11 +888,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 21460a3f5fbf640edcd3c97ab5cf46ce9c161a3d..8c2dff18ad11be3ba8ee472d3a57b04b8333d29e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.0.1?
 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 16206522825f1694da4e12ab76086dd4cd2f49c4..c18a99d375c40d104ad217a7094015f1d01eb61c 100644 (file)
@@ -1393,6 +1393,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;
         }
     }