Skip to content

Commit 7f55635

Browse files
committed
allow the first call to wcsxfrm to return ERANGE
If the output buffer provided to wcsxfrm is too small, errno is set to ERANGE. We should not error out in that case.
1 parent 8886d5f commit 7f55635

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Modules/_localemodule.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,11 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
263263
errno = 0;
264264
n2 = wcsxfrm(buf, s, n1);
265265
if (errno) {
266-
PyErr_SetFromErrno(PyExc_OSError);
267-
goto exit;
268-
}
269-
if (n2 >= (size_t)n1) {
266+
if (errno != ERANGE) {
267+
PyErr_SetFromErrno(PyExc_OSError);
268+
goto exit;
269+
}
270+
assert(n2 >= (size_t)n1);
270271
/* more space needed */
271272
wchar_t * new_buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));
272273
if (!new_buf) {

0 commit comments

Comments
 (0)