diff options
author | Walter Dörwald <walter@livinglogic.de> | 2003-10-24 14:25:28 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2003-10-24 14:25:28 (GMT) |
commit | 4894c306266b5fb3a6cf8429cbb6bc31d3e23e4e (patch) | |
tree | cb49811c63b1b476a07c19af8d8ab6f5d84ab3aa /Lib | |
parent | 6a5b02774284c20d6860edc16157cb99a0c0b3ca (diff) | |
download | cpython-4894c306266b5fb3a6cf8429cbb6bc31d3e23e4e.zip cpython-4894c306266b5fb3a6cf8429cbb6bc31d3e23e4e.tar.gz cpython-4894c306266b5fb3a6cf8429cbb6bc31d3e23e4e.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_codeccallbacks.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py index ae75229..289e838 100644 --- a/Lib/test/test_codeccallbacks.py +++ b/Lib/test/test_codeccallbacks.py @@ -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"<", + ord(">"): u">", + ord('"'): u""", + } + + 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) |