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
93434890
Commit
93434890
authored
May 03, 2014
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 21375: Fix possible Py_ssizet overflow in heapq.
parent
2460dc88
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
Modules/_heapqmodule.c
Modules/_heapqmodule.c
+8
-8
No files found.
Modules/_heapqmodule.c
View file @
93434890
...
...
@@ -86,7 +86,7 @@ _siftdown(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
static
int
_siftup
(
PyListObject
*
heap
,
Py_ssize_t
pos
)
{
Py_ssize_t
startpos
,
endpos
,
childpos
,
rightpos
;
Py_ssize_t
startpos
,
endpos
,
childpos
,
rightpos
,
limit
;
int
cmp
;
PyObject
*
newitem
,
*
tmp
,
*
olditem
;
Py_ssize_t
size
;
...
...
@@ -103,9 +103,10 @@ _siftup(PyListObject *heap, Py_ssize_t pos)
Py_INCREF
(
newitem
);
/* Bubble up the smaller child until hitting a leaf. */
childpos
=
2
*
pos
+
1
;
/* leftmost child position
*/
while
(
childpos
<
endpos
)
{
limit
=
endpos
/
2
;
/* smallest pos that has no child
*/
while
(
pos
<
limit
)
{
/* Set childpos to index of smaller child. */
childpos
=
2
*
pos
+
1
;
/* leftmost child position */
rightpos
=
childpos
+
1
;
if
(
rightpos
<
endpos
)
{
cmp
=
cmp_lt
(
...
...
@@ -131,7 +132,6 @@ _siftup(PyListObject *heap, Py_ssize_t pos)
PyList_SET_ITEM
(
heap
,
pos
,
tmp
);
Py_DECREF
(
olditem
);
pos
=
childpos
;
childpos
=
2
*
pos
+
1
;
if
(
size
!=
PyList_GET_SIZE
(
heap
))
{
PyErr_SetString
(
PyExc_RuntimeError
,
"list changed size during iteration"
);
...
...
@@ -439,7 +439,7 @@ _siftdownmax(PyListObject *heap, Py_ssize_t startpos, Py_ssize_t pos)
static
int
_siftupmax
(
PyListObject
*
heap
,
Py_ssize_t
pos
)
{
Py_ssize_t
startpos
,
endpos
,
childpos
,
rightpos
;
Py_ssize_t
startpos
,
endpos
,
childpos
,
rightpos
,
limit
;
int
cmp
;
PyObject
*
newitem
,
*
tmp
;
...
...
@@ -454,9 +454,10 @@ _siftupmax(PyListObject *heap, Py_ssize_t pos)
Py_INCREF
(
newitem
);
/* Bubble up the smaller child until hitting a leaf. */
childpos
=
2
*
pos
+
1
;
/* leftmost child position
*/
while
(
childpos
<
endpos
)
{
limit
=
endpos
/
2
;
/* smallest pos that has no child
*/
while
(
pos
<
limit
)
{
/* Set childpos to index of smaller child. */
childpos
=
2
*
pos
+
1
;
/* leftmost child position */
rightpos
=
childpos
+
1
;
if
(
rightpos
<
endpos
)
{
cmp
=
cmp_lt
(
...
...
@@ -475,7 +476,6 @@ _siftupmax(PyListObject *heap, Py_ssize_t pos)
Py_DECREF
(
PyList_GET_ITEM
(
heap
,
pos
));
PyList_SET_ITEM
(
heap
,
pos
,
tmp
);
pos
=
childpos
;
childpos
=
2
*
pos
+
1
;
}
/* The leaf at pos is empty now. Put newitem there, and bubble
...
...
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