diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-11-16 23:51:38 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-11-16 23:51:38 (GMT) |
commit | ee587eaa3668c5903acd9e93d46f269a7511d1c9 (patch) | |
tree | eab25f838d611d87820b71e02969f7dc5d01e221 /Python | |
parent | 1f7951711c16cca5f041288b81d01cb3021d0b7e (diff) | |
download | cpython-ee587eaa3668c5903acd9e93d46f269a7511d1c9.zip cpython-ee587eaa3668c5903acd9e93d46f269a7511d1c9.tar.gz cpython-ee587eaa3668c5903acd9e93d46f269a7511d1c9.tar.bz2 |
Catch PyUnicode_AS_UNICODE() errors in fileutils.c
Diffstat (limited to 'Python')
-rw-r--r-- | Python/fileutils.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c index c563eaa..0afa415 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -244,8 +244,12 @@ _Py_stat(PyObject *path, struct stat *statbuf) #ifdef MS_WINDOWS int err; 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) statbuf->st_mode = wstatbuf.st_mode; return err; @@ -297,14 +301,19 @@ FILE* _Py_fopen(PyObject *path, const char *mode) { #ifdef MS_WINDOWS + wchar_t *wpath; wchar_t wmode[10]; int usize; + wpath = PyUnicode_AsUnicode(path); + if (wpath == NULL) + return NULL; + usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode)); if (usize == 0) return NULL; - return _wfopen(PyUnicode_AS_UNICODE(path), wmode); + return _wfopen(wpath, wmode); #else FILE *f; PyObject *bytes = PyUnicode_EncodeFSDefault(path); |