mirror of https://github.com/python/cpython
_Py_wrealpath() uses _Py_char2wchar() to decode the result, to support
surrogate characters.
This commit is contained in:
parent
350147b5ca
commit
0a1b8cba90
|
@ -353,6 +353,7 @@ _Py_wrealpath(const wchar_t *path,
|
||||||
{
|
{
|
||||||
char *cpath;
|
char *cpath;
|
||||||
char cresolved_path[PATH_MAX];
|
char cresolved_path[PATH_MAX];
|
||||||
|
wchar_t *wresolved_path;
|
||||||
char *res;
|
char *res;
|
||||||
size_t r;
|
size_t r;
|
||||||
cpath = _Py_wchar2char(path);
|
cpath = _Py_wchar2char(path);
|
||||||
|
@ -364,11 +365,20 @@ _Py_wrealpath(const wchar_t *path,
|
||||||
PyMem_Free(cpath);
|
PyMem_Free(cpath);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
r = mbstowcs(resolved_path, cresolved_path, resolved_path_size);
|
|
||||||
if (r == (size_t)-1 || r >= PATH_MAX) {
|
wresolved_path = _Py_char2wchar(cresolved_path);
|
||||||
|
if (wresolved_path == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
r = wcslen(wresolved_path);
|
||||||
|
if (resolved_path_size <= r) {
|
||||||
|
PyMem_Free(wresolved_path);
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
wcsncpy(resolved_path, wresolved_path, resolved_path_size);
|
||||||
|
PyMem_Free(wresolved_path);
|
||||||
return resolved_path;
|
return resolved_path;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue