]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-130567: Remove optimistic allocation in locale.strxfrm() (GH-137143)
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 16 Oct 2025 07:54:41 +0000 (10:54 +0300)
committerGitHub <noreply@github.com>
Thu, 16 Oct 2025 07:54:41 +0000 (09:54 +0200)
commit2a2bc82cef9c6ae0b8de833e2b4aee37519de9d7
tree2ef3a03c5aff7cec6205a9225adf994bc47d7bcc
parent3a81313019ba82152653bd86f6ffd87dfe339c60
gh-130567: Remove optimistic allocation in locale.strxfrm() (GH-137143)

On modern systems, the result of wcsxfrm() is much larger the size of
the input string (from 4+2*n on Windows to 4+5*n on Linux for simple
ASCII strings), so optimistic allocation of the buffer of the same size
never works.

The exception is if the locale is "C" (or unset), but in that case the `wcsxfrm`
call should be fast (and calling `locale.strxfrm()` doesn't make too much
sense in the first place).
Modules/_localemodule.c