Skip to content

Commit 6d0f127

Browse files
gh-130567: Fix crash in locale.strxfrm() on macOS
1 parent 4ed046c commit 6d0f127

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Lib/test/test_locale.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ def test_strcoll_with_diacritic(self):
372372
def test_strxfrm_with_diacritic(self):
373373
self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
374374

375+
def test_xxx(self):
376+
bad = []
377+
for c in map(chr, range(1, 0x3000)):
378+
if c.isprintable():
379+
s = locale.strxfrm(c)
380+
if '\1' in s:
381+
bad += c
382+
print(f'{c!r} {c!a} -> {s!a}')
383+
self.fail(repr(''.join(bad)))
384+
375385

376386
class NormalizeTest(unittest.TestCase):
377387
def check(self, localename, expected):

Modules/_localemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
457457

458458
/* assume no change in size, first */
459459
n1 = n1 + 1;
460-
buf = PyMem_New(wchar_t, n1);
460+
buf = PyMem_New(wchar_t, n1+1);
461461
if (!buf) {
462462
PyErr_NoMemory();
463463
goto exit;

0 commit comments

Comments
 (0)