Kaydet (Commit) ee587eaa authored tarafından Victor Stinner's avatar Victor Stinner

Catch PyUnicode_AS_UNICODE() errors in fileutils.c

üst 1f795171
...@@ -244,8 +244,12 @@ _Py_stat(PyObject *path, struct stat *statbuf) ...@@ -244,8 +244,12 @@ _Py_stat(PyObject *path, struct stat *statbuf)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
int err; int err;
struct _stat wstatbuf; struct _stat wstatbuf;
wchar_t *wpath;
err = _wstat(PyUnicode_AS_UNICODE(path), &wstatbuf); wpath = PyUnicode_AsUnicode(path);
if (wpath == NULL)
return -1;
err = _wstat(wpath, &wstatbuf);
if (!err) if (!err)
statbuf->st_mode = wstatbuf.st_mode; statbuf->st_mode = wstatbuf.st_mode;
return err; return err;
...@@ -297,14 +301,19 @@ FILE* ...@@ -297,14 +301,19 @@ FILE*
_Py_fopen(PyObject *path, const char *mode) _Py_fopen(PyObject *path, const char *mode)
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
wchar_t *wpath;
wchar_t wmode[10]; wchar_t wmode[10];
int usize; int usize;
wpath = PyUnicode_AsUnicode(path);
if (wpath == NULL)
return NULL;
usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode)); usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode));
if (usize == 0) if (usize == 0)
return NULL; return NULL;
return _wfopen(PyUnicode_AS_UNICODE(path), wmode); return _wfopen(wpath, wmode);
#else #else
FILE *f; FILE *f;
PyObject *bytes = PyUnicode_EncodeFSDefault(path); PyObject *bytes = PyUnicode_EncodeFSDefault(path);
......
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