Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37bfa4e

Browse files
committed
Add a test for hashing of unaligned memory buffers (from issue #16427).
1 parent 1de1394 commit 37bfa4e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_hash.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ def test_coerced_floats(self):
4545
self.same_hash(int(1.23e300), float(1.23e300))
4646
self.same_hash(float(0.5), complex(0.5, 0.0))
4747

48+
def test_unaligned_buffers(self):
49+
# The hash function for bytes-like objects shouldn't have
50+
# alignment-dependent results (example in issue #16427).
51+
b = b"123456789abcdefghijklmnopqrstuvwxyz" * 128
52+
for i in range(16):
53+
for j in range(16):
54+
aligned = b[i:128+j]
55+
unaligned = memoryview(b)[i:128+j]
56+
self.assertEqual(hash(aligned), hash(unaligned))
57+
4858

4959
_default_hash = object.__hash__
5060
class DefaultHash(object): pass

0 commit comments

Comments
 (0)