diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-16 22:47:37 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-16 22:47:37 (GMT) |
commit | 3f711f4a3e6e2eb9ea9d9d0f841766e9df74ea29 (patch) | |
tree | 320e5f1bab23f23b29b403754fc70d4a49421e17 /Python | |
parent | 9d396399dad743124535dcb28cd073617ad15980 (diff) | |
download | cpython-3f711f4a3e6e2eb9ea9d9d0f841766e9df74ea29.zip cpython-3f711f4a3e6e2eb9ea9d9d0f841766e9df74ea29.tar.gz cpython-3f711f4a3e6e2eb9ea9d9d0f841766e9df74ea29.tar.bz2 |
_Py_wreadlink() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/fileutils.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index 076f510..cfafd86 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -307,6 +307,7 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) { char *cpath; char cbuf[PATH_MAX]; + wchar_t *wbuf; int res; size_t r1; @@ -324,11 +325,15 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t bufsiz) return -1; } cbuf[res] = '\0'; /* buf will be null terminated */ - r1 = mbstowcs(buf, cbuf, bufsiz); - if (r1 == -1) { + wbuf = _Py_char2wchar(cbuf); + r1 = wcslen(wbuf); + if (bufsiz <= r1) { + PyMem_Free(wbuf); errno = EINVAL; return -1; } + wcsncpy(buf, wbuf, bufsiz); + PyMem_Free(wbuf); return (int)r1; } #endif |