]> granicus.if.org Git - python/commitdiff
[ Bug #116636 ] Bug in StringIO.write()
authorGuido van Rossum <guido@python.org>
Thu, 12 Oct 2000 16:45:37 +0000 (16:45 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 12 Oct 2000 16:45:37 +0000 (16:45 +0000)
http://sourceforge.net/bugs/?func=detailbug&bug_id=116636&group_id=5470
bobalex@rsv.ricoh.com

Bug report: If the file position is less than the end of the "file",
and a write is performed extending past then end of the file, the data
string is corrupted.

Solution: in write(), when writing past the end, properly set self.len
when newpos is > self.len.

Lib/StringIO.py

index 334bf853a2c13b8db8bd50579f92eded8aadd70d..6952b1a999e75edfe6ab5ae3e6cc8048f8f1e6c4 100644 (file)
@@ -129,6 +129,8 @@ class StringIO:
                                self.buflist = []
                        self.buflist = [self.buf[:self.pos], s, self.buf[newpos:]]
                        self.buf = ''
+                       if newpos > self.len:
+                               self.len = newpos
                else:
                        self.buflist.append(s)
                        self.len = newpos