Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,33 +409,23 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
}

/* assume no change in size, first */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be updated to match changed code.

n1 = n1 + 1;
buf = PyMem_New(wchar_t, n1);
errno = 0;
n2 = wcsxfrm(NULL, s, 0);
if (errno && errno != ERANGE) {
PyErr_SetFromErrno(PyExc_OSError);
goto exit;
}
buf = PyMem_New(wchar_t, n2+1);
if (!buf) {
PyErr_NoMemory();
goto exit;
}
errno = 0;
n2 = wcsxfrm(buf, s, n1);
if (errno && errno != ERANGE) {
n2 = wcsxfrm(buf, s, n2+1);
if (errno) {
PyErr_SetFromErrno(PyExc_OSError);
goto exit;
}
if (n2 >= (size_t)n1) {
/* more space needed */
wchar_t * new_buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));
if (!new_buf) {
PyErr_NoMemory();
goto exit;
}
buf = new_buf;
errno = 0;
n2 = wcsxfrm(buf, s, n2+1);
if (errno) {
PyErr_SetFromErrno(PyExc_OSError);
goto exit;
}
}
result = PyUnicode_FromWideChar(buf, n2);
exit:
PyMem_Free(buf);
Expand Down
Loading