Kaydet (Commit) d60cd429 authored tarafından Larry Hastings's avatar Larry Hastings

Issue #14815: Bugfix: the PyLong fed into the seed generator must be unsigned.

üst 50c40006
...@@ -228,16 +228,17 @@ random_seed(RandomObject *self, PyObject *args) ...@@ -228,16 +228,17 @@ random_seed(RandomObject *self, PyObject *args)
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
/* If the arg is an int or long, use its absolute value; else use /* This algorithm relies on the number being unsigned.
* the absolute value of its hash code. * So: if the arg is a PyLong, use its absolute value.
* Otherwise use its hash value, cast to unsigned.
*/ */
if (PyLong_Check(arg)) if (PyLong_Check(arg))
n = PyNumber_Absolute(arg); n = PyNumber_Absolute(arg);
else { else {
Py_ssize_t hash = PyObject_Hash(arg); Py_hash_t hash = PyObject_Hash(arg);
if (hash == -1) if (hash == -1)
goto Done; goto Done;
n = PyLong_FromSsize_t(hash); n = PyLong_FromSize_t((size_t)hash);
} }
if (n == NULL) if (n == NULL)
goto Done; goto Done;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment