Kaydet (Commit) be487a65 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka Kaydeden (comit) GitHub

bpo-15954: Check return code of wcsxfrm(). (#508)

üst d908fd9e
...@@ -260,7 +260,12 @@ PyLocale_strxfrm(PyObject* self, PyObject* args) ...@@ -260,7 +260,12 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
PyErr_NoMemory(); PyErr_NoMemory();
goto exit; goto exit;
} }
errno = 0;
n2 = wcsxfrm(buf, s, n1); n2 = wcsxfrm(buf, s, n1);
if (errno) {
PyErr_SetFromErrno(PyExc_OSError);
goto exit;
}
if (n2 >= (size_t)n1) { if (n2 >= (size_t)n1) {
/* more space needed */ /* more space needed */
wchar_t * new_buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t)); wchar_t * new_buf = PyMem_Realloc(buf, (n2+1)*sizeof(wchar_t));
...@@ -269,14 +274,17 @@ PyLocale_strxfrm(PyObject* self, PyObject* args) ...@@ -269,14 +274,17 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
goto exit; goto exit;
} }
buf = new_buf; buf = new_buf;
errno = 0;
n2 = wcsxfrm(buf, s, n2+1); n2 = wcsxfrm(buf, s, n2+1);
if (errno) {
PyErr_SetFromErrno(PyExc_OSError);
goto exit;
}
} }
result = PyUnicode_FromWideChar(buf, n2); result = PyUnicode_FromWideChar(buf, n2);
exit: exit:
if (buf) PyMem_Free(buf);
PyMem_Free(buf); PyMem_Free(s);
if (s)
PyMem_Free(s);
return result; return result;
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment