mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Closes #15676: mmap: add empty file check prior to offset check
This commit is contained in:
parent
10fc104fed
commit
8b54d6d733
3 changed files with 24 additions and 0 deletions
|
@ -466,6 +466,22 @@ class MmapTests(unittest.TestCase):
|
|||
f.flush ()
|
||||
return mmap.mmap (f.fileno(), 0)
|
||||
|
||||
def test_empty_file (self):
|
||||
f = open (TESTFN, 'w+b')
|
||||
f.close()
|
||||
f = open(TESTFN, "rb")
|
||||
try:
|
||||
m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
|
||||
m.close()
|
||||
f.close()
|
||||
self.fail("should not have been able to mmap empty file")
|
||||
except ValueError as e:
|
||||
f.close()
|
||||
self.assertEqual(e.message, "cannot mmap an empty file")
|
||||
except:
|
||||
f.close()
|
||||
self.fail("unexpected exception: " + str(e))
|
||||
|
||||
def test_offset (self):
|
||||
f = open (TESTFN, 'w+b')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue