Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cffcc8b1
Commit
cffcc8b1
authored
Nov 19, 2006
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make cStringIO.truncate raise IOError for negative
arguments (even for -1). Fixes the last bit of #1359365.
parent
283a1353
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
1 deletion
+15
-1
Lib/test/test_StringIO.py
Lib/test/test_StringIO.py
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/cStringIO.c
Modules/cStringIO.c
+11
-1
No files found.
Lib/test/test_StringIO.py
View file @
cffcc8b1
...
...
@@ -62,6 +62,7 @@ class TestGenericStringIO(unittest.TestCase):
eq
(
f
.
getvalue
(),
'abcde'
)
f
.
write
(
'xyz'
)
eq
(
f
.
getvalue
(),
'abcdexyz'
)
self
.
assertRaises
(
IOError
,
f
.
truncate
,
-
1
)
f
.
close
()
self
.
assertRaises
(
ValueError
,
f
.
write
,
'frobnitz'
)
...
...
Misc/NEWS
View file @
cffcc8b1
...
...
@@ -101,6 +101,9 @@ Core and builtins
Library
-------
- cStringIO.truncate(-1) now raises an IOError, like StringIO and
regular files.
- Patch #1472877: Fix Tix subwidget name resolution.
- Patch #1594554: Always close a tkSimpleDialog on ok(), even
...
...
Modules/cStringIO.c
View file @
cffcc8b1
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment