Skip to content

Commit 6fda0a7

Browse files
committed
Fix string_size
Revert the string_size change. Instead, restore string_size to its previous value on error.
1 parent 00d23bb commit 6fda0a7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Modules/_io/bytesio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,12 @@ _io_BytesIO_truncate_impl(bytesio *self, PyObject *size)
759759
}
760760

761761
if (new_size < self->string_size) {
762+
Py_ssize_t old_string_size = self->string_size;
763+
self->string_size = new_size;
762764
if (resize_buffer_lock_held(self, new_size) < 0) {
765+
self->string_size = old_string_size;
763766
return NULL;
764767
}
765-
self->string_size = new_size;
766768
}
767769

768770
return PyLong_FromSsize_t(new_size);

0 commit comments

Comments
 (0)