diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-03-08 05:43:32 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-03-08 05:43:32 (GMT) |
commit | c9ffa068d1d1dc93f620994a532f219a4be08385 (patch) | |
tree | 5fcedce005ed23f1afd1eb221ce6a71dfc0bd5fb /Lib/test/test_mmap.py | |
parent | 02d2212c8ebadac24272541f2607a784415c606e (diff) | |
download | cpython-c9ffa068d1d1dc93f620994a532f219a4be08385.zip cpython-c9ffa068d1d1dc93f620994a532f219a4be08385.tar.gz cpython-c9ffa068d1d1dc93f620994a532f219a4be08385.tar.bz2 |
SF bug 515943: searching for data with \0 in mmap.
mmap_find_method(): this obtained the string to find via s#, but it
ignored its length, acting as if it were \0-terminated instead.
Someone please run on Linux too (the extended test_mmap works on Windows).
Bugfix candidate.
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r-- | Lib/test/test_mmap.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index f3d1538..0f34758 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -244,6 +244,31 @@ def test_both(): except OSError: pass + # Do a tougher .find() test. SF bug 515943 pointed out that, in 2.2, + # searching for data with embedded \0 bytes didn't work. + f = open(TESTFN, 'w+') + + try: # unlink TESTFN no matter what + data = 'aabaac\x00deef\x00\x00aa\x00' + n = len(data) + f.write(data) + m = mmap.mmap(f.fileno(), n) + f.close() + + for start in range(n+1): + for finish in range(start, n+1): + slice = data[start : finish] + vereq(m.find(slice), data.find(slice)) + vereq(m.find(slice + 'x'), -1) + + finally: + try: + os.unlink(TESTFN) + except OSError: + pass + + + print ' Test passed' test_both() |