bpo-35504: Fix a SystemError when delete the characters_written attribute of an OSError. (GH-11172)

This commit is contained in:
Serhiy Storchaka 2018-12-17 16:43:14 +02:00 committed by GitHub
parent fae95874b7
commit e2af34fcf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View file

@ -1196,6 +1196,14 @@ OSError_written_get(PyOSErrorObject *self, void *context)
static int
OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context)
{
if (arg == NULL) {
if (self->written == -1) {
PyErr_SetString(PyExc_AttributeError, "characters_written");
return -1;
}
self->written = -1;
return 0;
}
Py_ssize_t n;
n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
if (n == -1 && PyErr_Occurred())