]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport checkin:
authorWalter Dörwald <walter@livinglogic.de>
Thu, 5 Feb 2004 17:44:26 +0000 (17:44 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Thu, 5 Feb 2004 17:44:26 +0000 (17:44 +0000)
Fix reallocation bug in unicode.translate(): The code was comparing
characters instead of character pointers to determine space requirements.

Lib/test/test_unicode.py
Objects/unicodeobject.c

index 6e40b9faf31a80e6ef27aba13e9700d03dc8227d..eda7d223b2c4c8b1518fcabcea68f7586de20f9f 100644 (file)
@@ -129,6 +129,7 @@ class UnicodeTest(
         self.checkequalnofix(u'iiix', u'abababc', 'translate', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'})
         self.checkequalnofix(u'<i><i><i>c', u'abababc', 'translate', {ord('a'):None, ord('b'):u'<i>'})
         self.checkequalnofix(u'c', u'abababc', 'translate', {ord('a'):None, ord('b'):u''})
+        self.checkequalnofix(u'xyyx', u'xzx', 'translate', {ord('z'):u'yy'})
 
         self.assertRaises(TypeError, u'hello'.translate)
         self.assertRaises(TypeError, u'abababc'.translate, {ord('a'):''})
index b338e6120f6dd465a0e6260a976bfbdfd8cf5015..6f3e8b152220144239f57ba6e9c865ddcc0d0413 100644 (file)
@@ -3271,7 +3271,7 @@ int charmaptranslate_output(const Py_UNICODE *startinp, const Py_UNICODE *curinp
        else if (repsize!=0) {
            /* more than one character */
            int requiredsize = (*outp-PyUnicode_AS_UNICODE(*outobj)) +
-               (insize - (*curinp-*startinp)) +
+               (insize - (curinp-startinp)) +
                repsize - 1;
            if (charmaptranslate_makespace(outobj, outp, requiredsize))
                return -1;