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
c19bb327
Commit
c19bb327
authored
Jul 24, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #24620: Random.setstate() now validates the value of state last element.
parents
5b718d7f
178f0b6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
0 deletions
+11
-0
Lib/test/test_random.py
Lib/test/test_random.py
+5
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_randommodule.c
Modules/_randommodule.c
+4
-0
No files found.
Lib/test/test_random.py
View file @
c19bb327
...
@@ -338,6 +338,11 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
...
@@ -338,6 +338,11 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
self
.
assertRaises
(
TypeError
,
self
.
gen
.
setstate
,
(
2
,
(
'a'
,)
*
625
,
None
))
self
.
assertRaises
(
TypeError
,
self
.
gen
.
setstate
,
(
2
,
(
'a'
,)
*
625
,
None
))
# Last element s/b an int also
# Last element s/b an int also
self
.
assertRaises
(
TypeError
,
self
.
gen
.
setstate
,
(
2
,
(
0
,)
*
624
+
(
'a'
,),
None
))
self
.
assertRaises
(
TypeError
,
self
.
gen
.
setstate
,
(
2
,
(
0
,)
*
624
+
(
'a'
,),
None
))
# Last element s/b between 0 and 624
with
self
.
assertRaises
((
ValueError
,
OverflowError
)):
self
.
gen
.
setstate
((
2
,
(
1
,)
*
624
+
(
625
,),
None
))
with
self
.
assertRaises
((
ValueError
,
OverflowError
)):
self
.
gen
.
setstate
((
2
,
(
1
,)
*
624
+
(
-
1
,),
None
))
# Little trick to make "tuple(x % (2**32) for x in internalstate)"
# Little trick to make "tuple(x % (2**32) for x in internalstate)"
# raise ValueError. I cannot think of a simple way to achieve this, so
# raise ValueError. I cannot think of a simple way to achieve this, so
...
...
Misc/NEWS
View file @
c19bb327
...
@@ -28,6 +28,8 @@ Core and Builtins
...
@@ -28,6 +28,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue #24620: Random.setstate() now validates the value of state last element.
- Issue #22485: Fixed an issue that caused `inspect.getsource` to return incorrect
- Issue #22485: Fixed an issue that caused `inspect.getsource` to return incorrect
results on nested functions.
results on nested functions.
...
...
Modules/_randommodule.c
View file @
c19bb327
...
@@ -335,6 +335,10 @@ random_setstate(RandomObject *self, PyObject *state)
...
@@ -335,6 +335,10 @@ random_setstate(RandomObject *self, PyObject *state)
index
=
PyLong_AsLong
(
PyTuple_GET_ITEM
(
state
,
i
));
index
=
PyLong_AsLong
(
PyTuple_GET_ITEM
(
state
,
i
));
if
(
index
==
-
1
&&
PyErr_Occurred
())
if
(
index
==
-
1
&&
PyErr_Occurred
())
return
NULL
;
return
NULL
;
if
(
index
<
0
||
index
>
N
)
{
PyErr_SetString
(
PyExc_ValueError
,
"invalid state"
);
return
NULL
;
}
self
->
index
=
(
int
)
index
;
self
->
index
=
(
int
)
index
;
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
...
...
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