Issue #23796: peak and read1 methods of BufferedReader now raise ValueError
if they called on a closed object.
Patch by John Hergenroeder.
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 3606cc8..365bb85 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -889,6 +889,8 @@
PyObject *res = NULL;
CHECK_INITIALIZED(self)
+ CHECK_CLOSED(self, "peek of closed file")
+
if (!PyArg_ParseTuple(args, "|n:peek", &n)) {
return NULL;
}
@@ -963,6 +965,9 @@
"read length must be positive");
return NULL;
}
+
+ CHECK_CLOSED(self, "read of closed file")
+
if (n == 0)
return PyBytes_FromStringAndSize(NULL, 0);