diff options
| author | Mark Dickinson <mdickinson@enthought.com> | 2011-09-24 17:18:40 (GMT) |
|---|---|---|
| committer | Mark Dickinson <mdickinson@enthought.com> | 2011-09-24 17:18:40 (GMT) |
| commit | 57e683e53eed1455176b17304b3ac007ae7eb181 (patch) | |
| tree | 983e172ad16aaaf227f4d56d34cafc416fea68eb /Objects/unicodeobject.c | |
| parent | 0390151100e3035be8a9cca8b180a63fa19d1368 (diff) | |
| download | cpython-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/unicodeobject.c')
| -rw-r--r-- | Objects/unicodeobject.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 8c2ce6a..a85bac8 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -7721,22 +7721,22 @@ unicode_getitem(PyUnicodeObject *self, Py_ssize_t index) } /* Believe it or not, this produces the same value for ASCII strings - as string_hash(). */ + as bytes_hash(). */ static Py_hash_t unicode_hash(PyUnicodeObject *self) { Py_ssize_t len; Py_UNICODE *p; - Py_hash_t x; + Py_uhash_t x; if (self->hash != -1) return self->hash; len = Py_SIZE(self); p = self->str; - x = *p << 7; + x = (Py_uhash_t)*p << 7; while (--len >= 0) - x = (1000003*x) ^ *p++; - x ^= Py_SIZE(self); + x = (1000003U*x) ^ (Py_uhash_t)*p++; + x ^= (Py_uhash_t)Py_SIZE(self); if (x == -1) x = -2; self->hash = x; |
