Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().

charmaptranslate_makespace() allocated more memory than required for the
next replacement but didn't remember that fact, so memory size was growing
exponentially every time a replacement string is longer that one character.
This fixes SF bug #828737.
This commit is contained in:
Walter Dörwald 2003-10-24 14:25:28 +00:00
parent 6a5b027742
commit 4894c30626
2 changed files with 32 additions and 19 deletions

View file

@ -690,6 +690,18 @@ class CodecCallbackTest(unittest.TestCase):
self.assertRaises(TypeError, u"\xff".translate, {0xff: sys.maxunicode+1})
self.assertRaises(TypeError, u"\xff".translate, {0xff: ()})
def test_bug828737(self):
charmap = {
ord("&"): u"&",
ord("<"): u"&lt;",
ord(">"): u"&gt;",
ord('"'): u"&quot;",
}
for n in (1, 10, 100, 1000):
text = u'abc<def>ghi'*n
text.translate(charmap)
def test_main():
test.test_support.run_unittest(CodecCallbackTest)