diff options
author | Larry Hastings <larry@hastings.org> | 2012-06-24 09:52:21 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2012-06-24 09:52:21 (GMT) |
commit | d60cd4295c78fd8703c40bbbaf67e139315f1d4a (patch) | |
tree | f08d6464950d3c199268dc8dee4d45fbef663de3 /Modules/_randommodule.c | |
parent | 50c4000685412124a1817815bcbaae83f6bd9666 (diff) | |
download | cpython-d60cd4295c78fd8703c40bbbaf67e139315f1d4a.zip cpython-d60cd4295c78fd8703c40bbbaf67e139315f1d4a.tar.gz cpython-d60cd4295c78fd8703c40bbbaf67e139315f1d4a.tar.bz2 |
Issue #14815: Bugfix: the PyLong fed into the seed generator must be unsigned.
Diffstat (limited to 'Modules/_randommodule.c')
-rw-r--r-- | Modules/_randommodule.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 52530e6..421a0d8 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -228,16 +228,17 @@ random_seed(RandomObject *self, PyObject *args) Py_INCREF(Py_None); return Py_None; } - /* If the arg is an int or long, use its absolute value; else use - * the absolute value of its hash code. + /* This algorithm relies on the number being unsigned. + * So: if the arg is a PyLong, use its absolute value. + * Otherwise use its hash value, cast to unsigned. */ if (PyLong_Check(arg)) n = PyNumber_Absolute(arg); else { - Py_ssize_t hash = PyObject_Hash(arg); + Py_hash_t hash = PyObject_Hash(arg); if (hash == -1) goto Done; - n = PyLong_FromSsize_t(hash); + n = PyLong_FromSize_t((size_t)hash); } if (n == NULL) goto Done; |