From: Walter Dörwald Date: Thu, 5 Feb 2004 17:36:00 +0000 (+0000) Subject: Fix reallocation bug in unicode.translate(): The code was comparing X-Git-Tag: v2.4a1~873 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd736e71a3d35d870c2ff89b90a39050553a2453;p=python Fix reallocation bug in unicode.translate(): The code was comparing characters instead of character pointers to determine space requirements. --- diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 18a2d46ba9..5ce2842f4e 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -136,6 +136,7 @@ class UnicodeTest( self.checkequalnofix(u'iiix', u'abababc', 'translate', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'}) self.checkequalnofix(u'c', u'abababc', 'translate', {ord('a'):None, ord('b'):u''}) 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'):''}) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a218ddb6eb..e3bef57540 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3283,7 +3283,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;