mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-31478: Fix an assertion failure in random.seed() in case a seed has a bad __abs__() method. (#3596)
This commit is contained in:
parent
db50ba7c72
commit
d780b2d588
3 changed files with 18 additions and 2 deletions
|
@ -259,8 +259,11 @@ random_seed(RandomObject *self, PyObject *args)
|
|||
* 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);
|
||||
if (PyLong_Check(arg)) {
|
||||
/* Calling int.__abs__() prevents calling arg.__abs__(), which might
|
||||
return an invalid value. See issue #31478. */
|
||||
n = PyLong_Type.tp_as_number->nb_absolute(arg);
|
||||
}
|
||||
else {
|
||||
Py_hash_t hash = PyObject_Hash(arg);
|
||||
if (hash == -1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue