mirror of https://github.com/python/cpython
Py_Main() uses _Py_wchar2char() to encode the filename in error messages
This commit is contained in:
parent
89f3ad10d2
commit
9a6692f6d7
|
@ -637,19 +637,19 @@ Py_Main(int argc, wchar_t **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sts==-1 && filename!=NULL) {
|
if (sts==-1 && filename!=NULL) {
|
||||||
if ((fp = _Py_wfopen(filename, L"r")) == NULL) {
|
fp = _Py_wfopen(filename, L"r");
|
||||||
char cfilename[PATH_MAX];
|
if (fp == NULL) {
|
||||||
size_t r = wcstombs(cfilename, filename, PATH_MAX);
|
char *cfilename_buffer;
|
||||||
if (r == PATH_MAX)
|
const char *cfilename;
|
||||||
/* cfilename is not null-terminated;
|
cfilename_buffer = _Py_wchar2char(filename);
|
||||||
* forcefully null-terminating it
|
if (cfilename_buffer != NULL)
|
||||||
* might break the shift state */
|
cfilename = cfilename_buffer;
|
||||||
strcpy(cfilename, "<file name too long>");
|
else
|
||||||
if (r == ((size_t)-1))
|
cfilename = "<unprintable file name>";
|
||||||
strcpy(cfilename, "<unprintable file name>");
|
|
||||||
fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n",
|
fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n",
|
||||||
argv[0], cfilename, errno, strerror(errno));
|
argv[0], cfilename, errno, strerror(errno));
|
||||||
|
if (cfilename_buffer)
|
||||||
|
PyMem_Free(cfilename_buffer);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
else if (skipfirstline) {
|
else if (skipfirstline) {
|
||||||
|
|
Loading…
Reference in New Issue