Issue #12062: Fix a flushing bug when doing a certain type of I/O sequence

on a file opened in read+write mode (namely: reading, seeking a bit forward,
writing, then seeking before the previous write but still within buffered
data, and writing again).
This commit is contained in:
Antoine Pitrou 2011-05-13 00:16:28 +02:00
commit 00dd182b8e
3 changed files with 33 additions and 1 deletions

View file

@ -1838,7 +1838,7 @@ bufferedwriter_write(buffered *self, PyObject *args)
avail = Py_SAFE_DOWNCAST(self->buffer_size - self->pos, Py_off_t, Py_ssize_t);
if (buf.len <= avail) {
memcpy(self->buffer + self->pos, buf.buf, buf.len);
if (!VALID_WRITE_BUFFER(self)) {
if (!VALID_WRITE_BUFFER(self) || self->write_pos > self->pos) {
self->write_pos = self->pos;
}
ADJUST_POSITION(self, self->pos + buf.len);