From 8c077f99d0ee7a513dc29e29cbfa0f40be4a57ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Walter=20D=C3=B6rwald?= Date: Thu, 5 Feb 2004 17:44:26 +0000 Subject: Backport checkin: Fix reallocation bug in unicode.translate(): The code was comparing characters instead of character pointers to determine space requirements. --- Lib/test/test_unicode.py | 1 + Objects/unicodeobject.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 6e40b9f..eda7d22 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -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'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 b338e61..6f3e8b1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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; -- cgit v0.12