mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
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:
parent
6a5b027742
commit
4894c30626
2 changed files with 32 additions and 19 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue