Skip to content

Commit e018b30

Browse files
committed
On Windows fileno(stdout) and fileno(stderr) can return an invalid file descriptor number (-2 on my machine). It happens only for pythonw.exe but not for python.exe. Catch the problem ASAP in PyFile_NewStdPrinter(). I've also removed the call to PyErr_BadInternalCall(). It was causing a seg fault because the exceptions aren't available yet.
1 parent 3ab4f65 commit e018b30

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Objects/fileobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ PyFile_NewStdPrinter(int fd)
352352
{
353353
PyStdPrinter_Object *self;
354354

355-
if (fd != fileno(stdout) && fd != fileno(stderr)) {
356-
PyErr_BadInternalCall();
355+
if ((fd != fileno(stdout) && fd != fileno(stderr)) || fd < 0) {
356+
/* not enough infrastructure for PyErr_BadInternalCall() */
357357
return NULL;
358358
}
359359

0 commit comments

Comments
 (0)