Query the result size with a real one-element buffer instead of
wcsxfrm(NULL, s, 0): DragonFly BSD's wcsxfrm() crashes when the
destination is NULL or the size is 0.
(cherry picked from commit
f389b03f9f2768342bfd49987a257460d4aa4faf)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
--- /dev/null
+Fix a crash in :func:`locale.strxfrm` on DragonFly BSD,
+whose ``wcsxfrm()`` does not support the zero size.
{
Py_ssize_t n1;
wchar_t *s = NULL, *buf = NULL;
+ wchar_t dummy[1];
size_t n2;
PyObject *result = NULL;
}
errno = 0;
- n2 = wcsxfrm(NULL, s, 0);
+ /* Query the size with a real one-element buffer: DragonFly BSD's
+ wcsxfrm() crashes when the destination is NULL or the size is 0. */
+ n2 = wcsxfrm(dummy, s, 1);
if (errno && errno != ERANGE) {
PyErr_SetFromErrno(PyExc_OSError);
goto exit;