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
da4210f7
Commit
da4210f7
authored
Apr 15, 2012
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Plain Diff
Issue #13496: Merge from 3.2
parents
b0f00476
a13b109b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
+18
-2
Lib/test/test_bisect.py
Lib/test/test_bisect.py
+7
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_bisectmodule.c
Modules/_bisectmodule.c
+8
-2
No files found.
Lib/test/test_bisect.py
View file @
da4210f7
...
@@ -122,6 +122,13 @@ class TestBisect(unittest.TestCase):
...
@@ -122,6 +122,13 @@ class TestBisect(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
mod
.
insort_left
,
[
1
,
2
,
3
],
5
,
-
1
,
3
),
self
.
assertRaises
(
ValueError
,
mod
.
insort_left
,
[
1
,
2
,
3
],
5
,
-
1
,
3
),
self
.
assertRaises
(
ValueError
,
mod
.
insort_right
,
[
1
,
2
,
3
],
5
,
-
1
,
3
),
self
.
assertRaises
(
ValueError
,
mod
.
insort_right
,
[
1
,
2
,
3
],
5
,
-
1
,
3
),
def
test_large_range
(
self
):
# Issue 13496
mod
=
self
.
module
data
=
range
(
sys
.
maxsize
-
1
)
self
.
assertEqual
(
mod
.
bisect_left
(
data
,
sys
.
maxsize
-
3
),
sys
.
maxsize
-
3
)
self
.
assertEqual
(
mod
.
bisect_right
(
data
,
sys
.
maxsize
-
3
),
sys
.
maxsize
-
2
)
def
test_random
(
self
,
n
=
25
):
def
test_random
(
self
,
n
=
25
):
from
random
import
randrange
from
random
import
randrange
for
i
in
range
(
n
):
for
i
in
range
(
n
):
...
...
Misc/NEWS
View file @
da4210f7
...
@@ -29,6 +29,9 @@ Core and Builtins
...
@@ -29,6 +29,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #13496: Fix potential overflow in bisect.bisect algorithm when applied
to a collection of size > sys.maxsize / 2.
- Have importlib take advantage of ImportError'
s
new
'name'
and
'path'
- Have importlib take advantage of ImportError'
s
new
'name'
and
'path'
attributes
.
attributes
.
...
...
Modules/_bisectmodule.c
View file @
da4210f7
...
@@ -21,7 +21,10 @@ internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t
...
@@ -21,7 +21,10 @@ internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t
return
-
1
;
return
-
1
;
}
}
while
(
lo
<
hi
)
{
while
(
lo
<
hi
)
{
mid
=
(
lo
+
hi
)
/
2
;
/* The (size_t)cast ensures that the addition and subsequent division
are performed as unsigned operations, avoiding difficulties from
signed overflow. (See issue 13496.) */
mid
=
((
size_t
)
lo
+
hi
)
/
2
;
litem
=
PySequence_GetItem
(
list
,
mid
);
litem
=
PySequence_GetItem
(
list
,
mid
);
if
(
litem
==
NULL
)
if
(
litem
==
NULL
)
return
-
1
;
return
-
1
;
...
@@ -123,7 +126,10 @@ internal_bisect_left(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t h
...
@@ -123,7 +126,10 @@ internal_bisect_left(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t h
return
-
1
;
return
-
1
;
}
}
while
(
lo
<
hi
)
{
while
(
lo
<
hi
)
{
mid
=
(
lo
+
hi
)
/
2
;
/* The (size_t)cast ensures that the addition and subsequent division
are performed as unsigned operations, avoiding difficulties from
signed overflow. (See issue 13496.) */
mid
=
((
size_t
)
lo
+
hi
)
/
2
;
litem
=
PySequence_GetItem
(
list
,
mid
);
litem
=
PySequence_GetItem
(
list
,
mid
);
if
(
litem
==
NULL
)
if
(
litem
==
NULL
)
return
-
1
;
return
-
1
;
...
...
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