diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-06 19:21:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-06 19:21:41 (GMT) |
commit | be487a65f18e1be5fde03e2977fff4be53cc2fbf (patch) | |
tree | 680cef96de35559eb9b476fb9ac0d80b63f4ee1b /Modules | |
parent | d908fd9ee1c307f7066023eb2031c0f509036cbc (diff) | |
download | cpython-be487a65f18e1be5fde03e2977fff4be53cc2fbf.zip cpython-be487a65f18e1be5fde03e2977fff4be53cc2fbf.tar.gz cpython-be487a65f18e1be5fde03e2977fff4be53cc2fbf.tar.bz2 |
bpo-15954: Check return code of wcsxfrm(). (#508)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_localemodule.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index feb3802..f5c126a 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -260,7 +260,12 @@ PyLocale_strxfrm(PyObject* self, PyObject* args) PyErr_NoMemory(); goto exit; } + errno = 0; n2 = wcsxfrm(buf, s, n1); + 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)); @@ -269,14 +274,17 @@ PyLocale_strxfrm(PyObject* self, PyObject* args) 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: - if (buf) - PyMem_Free(buf); - if (s) - PyMem_Free(s); + PyMem_Free(buf); + PyMem_Free(s); return result; } #endif |