[Jython-checkins] jython: Make cStringIO throw IOError when a negative argument is passed to truncate.

frank.wierzbicki jython-checkins at python.org
Thu Sep 22 05:45:42 CEST 2011


http://hg.python.org/jython/rev/a95ffe555a27
changeset:   6247:a95ffe555a27
user:        Frank Wierzbicki <fwierzbicki at gmail.com>
date:        Sat Sep 17 20:37:43 2011 -0700
summary:
  Make cStringIO throw IOError when a negative argument is passed to truncate.

files:
  src/org/python/modules/cStringIO.java |  9 ++++++---
  1 files changed, 6 insertions(+), 3 deletions(-)


diff --git a/src/org/python/modules/cStringIO.java b/src/org/python/modules/cStringIO.java
--- a/src/org/python/modules/cStringIO.java
+++ b/src/org/python/modules/cStringIO.java
@@ -11,6 +11,7 @@
 
 package org.python.modules;
 
+import com.kenai.constantine.platform.Errno;
 import org.python.core.Py;
 import org.python.core.PyIterator;
 import org.python.core.PyList;
@@ -298,14 +299,17 @@
         /**
          * truncate the file at the current position.
          */
-        public void truncate() {
-            truncate(-1);
+        public synchronized void truncate() {
+            buf.setLength(this.pos);
         }
 
         /**
          * truncate the file at the position pos.
          */
         public synchronized void truncate(long pos) {
+            if (pos < 0) {
+                throw Py.IOError(Errno.EINVAL, "Negative size not allowed");
+            }
             int pos_int = _convert_to_int(pos);
             if (pos_int < 0)
                 pos_int = this.pos;
@@ -313,7 +317,6 @@
             this.pos = pos_int;
         }
 
-
         /**
          * Write a string to the file.
          * @param obj     The data to write.

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list