summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-11-19 10:41:41 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-11-19 10:41:41 (GMT)
commitcffcc8b195d0086d6089ac4563ac17b4c95471e3 (patch)
tree0e082ae41d65af0c069a5df47c70354827ddb830 /Modules
parent283a1353a0834d53b230b22e8db9e7b4fcd220d0 (diff)
downloadcpython-cffcc8b195d0086d6089ac4563ac17b4c95471e3.zip
cpython-cffcc8b195d0086d6089ac4563ac17b4c95471e3.tar.gz
cpython-cffcc8b195d0086d6089ac4563ac17b4c95471e3.tar.bz2
Make cStringIO.truncate raise IOError for negative
arguments (even for -1). Fixes the last bit of #1359365.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/cStringIO.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 100891b..3f762b0 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -289,7 +289,17 @@ IO_truncate(IOobject *self, PyObject *args) {
if (!IO__opencheck(self)) return NULL;
if (!PyArg_ParseTuple(args, "|n:truncate", &pos)) return NULL;
- if (pos < 0) pos = self->pos;
+
+ if (PyTuple_Size(args) == 0) {
+ /* No argument passed, truncate to current position */
+ pos = self->pos;
+ }
+
+ if (pos < 0) {
+ errno = EINVAL;
+ PyErr_SetFromErrno(PyExc_IOError);
+ return NULL;
+ }
if (self->string_size > pos) self->string_size = pos;
self->pos = self->string_size;