summaryrefslogtreecommitdiffstats
path: root/Objects/tupleobject.c
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2011-09-24 17:18:40 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2011-09-24 17:18:40 (GMT)
commit57e683e53eed1455176b17304b3ac007ae7eb181 (patch)
tree983e172ad16aaaf227f4d56d34cafc416fea68eb /Objects/tupleobject.c
parent0390151100e3035be8a9cca8b180a63fa19d1368 (diff)
downloadcpython-57e683e53eed1455176b17304b3ac007ae7eb181.zip
cpython-57e683e53eed1455176b17304b3ac007ae7eb181.tar.gz
cpython-57e683e53eed1455176b17304b3ac007ae7eb181.tar.bz2
Issue #1621: Fix undefined behaviour in bytes.__hash__, str.__hash__, tuple.__hash__, frozenset.__hash__ and set indexing operations.
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r--Objects/tupleobject.c9
1 files changed, 5 insertions, 4 deletions
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 @@ Done:
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 @@ tuplehash(PyTupleObject *v)
mult += (Py_hash_t)(82520L + len + len);
}
x += 97531L;
- if (x == -1)
+ if (x == (Py_uhash_t)-1)
x = -2;
return x;
}