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
9f8900ed
Commit
9f8900ed
authored
Feb 07, 2007
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not let overflows in enumerate() and count() pass silently.
parent
3994f786
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
2 deletions
+16
-2
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+1
-2
Misc/NEWS
Misc/NEWS
+4
-0
Modules/itertoolsmodule.c
Modules/itertoolsmodule.c
+5
-0
Objects/enumobject.c
Objects/enumobject.c
+6
-0
No files found.
Lib/test/test_itertools.py
View file @
9f8900ed
...
...
@@ -52,8 +52,7 @@ class TestBasicOps(unittest.TestCase):
self
.
assertEqual
(
take
(
2
,
zip
(
'abc'
,
count
(
3
))),
[(
'a'
,
3
),
(
'b'
,
4
)])
self
.
assertRaises
(
TypeError
,
count
,
2
,
3
)
self
.
assertRaises
(
TypeError
,
count
,
'a'
)
c
=
count
(
sys
.
maxint
-
2
)
# verify that rollover doesn't crash
c
.
next
();
c
.
next
();
c
.
next
();
c
.
next
();
c
.
next
()
self
.
assertRaises
(
OverflowError
,
list
,
islice
(
count
(
sys
.
maxint
-
5
),
10
))
c
=
count
(
3
)
self
.
assertEqual
(
repr
(
c
),
'count(3)'
)
c
.
next
()
...
...
Misc/NEWS
View file @
9f8900ed
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.5.1c1?
Core and builtins
-----------------
- SF #151204: enumerate() now raises an Overflow error at sys.maxint items.
- Bug #1377858: Fix the segfaulting of the interpreter when an object created
a weakref on itself during a __del__ call for new-style classes (classic
classes still have the bug).
...
...
@@ -103,6 +105,8 @@ Core and builtins
Extension
Modules
-----------------
-
operator
.
count
()
now
raises
an
OverflowError
when
the
count
reaches
sys
.
maxint
.
-
Bug
#
1575169
:
operator
.
isSequenceType
()
now
returns
False
for
subclasses
of
dict
.
-
collections
.
defaultdict
()
now
verifies
that
the
factory
function
is
callable
.
...
...
Modules/itertoolsmodule.c
View file @
9f8900ed
...
...
@@ -2073,6 +2073,11 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static
PyObject
*
count_next
(
countobject
*
lz
)
{
if
(
lz
->
cnt
==
LONG_MAX
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"cannot count beyond LONG_MAX"
);
return
NULL
;
}
return
PyInt_FromSsize_t
(
lz
->
cnt
++
);
}
...
...
Objects/enumobject.c
View file @
9f8900ed
...
...
@@ -62,6 +62,12 @@ enum_next(enumobject *en)
PyObject
*
result
=
en
->
en_result
;
PyObject
*
it
=
en
->
en_sit
;
if
(
en
->
en_index
==
LONG_MAX
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"enumerate() is limited to LONG_MAX items"
);
return
NULL
;
}
next_item
=
(
*
it
->
ob_type
->
tp_iternext
)(
it
);
if
(
next_item
==
NULL
)
return
NULL
;
...
...
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