summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-09-28 07:50:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-28 07:50:01 (GMT)
commitd780b2d588e68bd7047ef5d1f04e36da38b7a350 (patch)
treed673be6c4ee93bd5c462fdd0d3f520226a09d623 /Modules
parentdb50ba7c72bd5f0617c50df3f1a1bb8b26955882 (diff)
downloadcpython-d780b2d588e68bd7047ef5d1f04e36da38b7a350.zip
cpython-d780b2d588e68bd7047ef5d1f04e36da38b7a350.tar.gz
cpython-d780b2d588e68bd7047ef5d1f04e36da38b7a350.tar.bz2
bpo-31478: Fix an assertion failure in random.seed() in case a seed has a bad __abs__() method. (#3596)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_randommodule.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 747a547..51677f8 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -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)