summaryrefslogtreecommitdiffstats
path: root/Modules/_randommodule.c
diff options
context:
space:
mode:
authorMariatta <Mariatta@users.noreply.github.com>2017-05-27 14:20:24 (GMT)
committerGitHub <noreply@github.com>2017-05-27 14:20:24 (GMT)
commit94d8261d1ca3f0c551d9d43a4db342d806af7a6a (patch)
treeaf4733952811ac9d070aec3217c969f345129109 /Modules/_randommodule.c
parentb52c68a5a3f546cbbe1589f8bb3e51bfd55a6c15 (diff)
downloadcpython-94d8261d1ca3f0c551d9d43a4db342d806af7a6a.zip
cpython-94d8261d1ca3f0c551d9d43a4db342d806af7a6a.tar.gz
cpython-94d8261d1ca3f0c551d9d43a4db342d806af7a6a.tar.bz2
[3.6] bpo-29960 _random.Random corrupted on exception in setstate(). … (#1287)
(cherry picked from commit 9616a82e7802241a4b74cf7ae38d43c37bf66e48)
Diffstat (limited to 'Modules/_randommodule.c')
-rw-r--r--Modules/_randommodule.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index e5dd2c9..d006aeb 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -348,6 +348,7 @@ random_setstate(RandomObject *self, PyObject *state)
int i;
unsigned long element;
long index;
+ uint32_t new_state[N];
if (!PyTuple_Check(state)) {
PyErr_SetString(PyExc_TypeError,
@@ -364,7 +365,7 @@ random_setstate(RandomObject *self, PyObject *state)
element = PyLong_AsUnsignedLong(PyTuple_GET_ITEM(state, i));
if (element == (unsigned long)-1 && PyErr_Occurred())
return NULL;
- self->state[i] = (uint32_t)element;
+ new_state[i] = (uint32_t)element;
}
index = PyLong_AsLong(PyTuple_GET_ITEM(state, i));
@@ -375,6 +376,8 @@ random_setstate(RandomObject *self, PyObject *state)
return NULL;
}
self->index = (int)index;
+ for (i = 0; i < N; i++)
+ self->state[i] = new_state[i];
Py_INCREF(Py_None);
return Py_None;