diff --git a/Objects/fileobject.c b/Objects/fileobject.c index c6c7d8e2009..c4feed1304e 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -352,8 +352,8 @@ PyFile_NewStdPrinter(int fd) { PyStdPrinter_Object *self; - if (fd != fileno(stdout) && fd != fileno(stderr)) { - PyErr_BadInternalCall(); + if ((fd != fileno(stdout) && fd != fileno(stderr)) || fd < 0) { + /* not enough infrastructure for PyErr_BadInternalCall() */ return NULL; }