Issue #1621: Fix undefined behaviour in bytes.__hash__, str.__hash__, tuple.__hash__, frozenset.__hash__ and set indexing operations.
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index ccfd281..ddb69e4 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -315,11 +315,12 @@
static Py_hash_t
tuplehash(PyTupleObject *v)
{
- register Py_hash_t x, y;
+ register Py_uhash_t x;
+ register Py_hash_t y;
register Py_ssize_t len = Py_SIZE(v);
register PyObject **p;
- Py_hash_t mult = 1000003L;
- x = 0x345678L;
+ Py_uhash_t mult = 1000003;
+ x = 0x345678;
p = v->ob_item;
while (--len >= 0) {
y = PyObject_Hash(*p++);
@@ -330,7 +331,7 @@
mult += (Py_hash_t)(82520L + len + len);
}
x += 97531L;
- if (x == -1)
+ if (x == (Py_uhash_t)-1)
x = -2;
return x;
}