mirror of
https://github.com/python/cpython.git
synced 2025-10-09 08:31:26 +00:00
Issue #1621: Fix undefined behaviour in bytes.__hash__, str.__hash__, tuple.__hash__, frozenset.__hash__ and set indexing operations.
This commit is contained in:
parent
0390151100
commit
57e683e53e
5 changed files with 26 additions and 25 deletions
|
@ -869,16 +869,16 @@ bytes_hash(PyBytesObject *a)
|
|||
{
|
||||
register Py_ssize_t len;
|
||||
register unsigned char *p;
|
||||
register Py_hash_t x;
|
||||
register Py_uhash_t x;
|
||||
|
||||
if (a->ob_shash != -1)
|
||||
return a->ob_shash;
|
||||
len = Py_SIZE(a);
|
||||
p = (unsigned char *) a->ob_sval;
|
||||
x = *p << 7;
|
||||
x = (Py_uhash_t)*p << 7;
|
||||
while (--len >= 0)
|
||||
x = (1000003*x) ^ *p++;
|
||||
x ^= Py_SIZE(a);
|
||||
x = (1000003U*x) ^ (Py_uhash_t)*p++;
|
||||
x ^= (Py_uhash_t)Py_SIZE(a);
|
||||
if (x == -1)
|
||||
x = -2;
|
||||
a->ob_shash = x;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue