Skip to content

Commit

Permalink
mavutil: correct processing of zero-length logs
Browse files Browse the repository at this point in the history
can't mmap a zero-length file
  • Loading branch information
peterbarker committed Aug 14, 2024
1 parent 533161c commit 1b02514
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions mavutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,14 @@ def __init__(self, filename, progress_callback=None):
self.f.seek(0, 2)
self.data_len = self.f.tell()
self.f.seek(0)
if platform.system() == "Windows":
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, None, mmap.ACCESS_READ)
else:
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, mmap.MAP_PRIVATE, mmap.PROT_READ)
self._rewind()
self.init_arrays(progress_callback)
self.data_map = None
if self.data_len != 0:
if platform.system() == "Windows":
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, None, mmap.ACCESS_READ)
else:
self.data_map = mmap.mmap(self.f.fileno(), self.data_len, mmap.MAP_PRIVATE, mmap.PROT_READ)
self._rewind()
self.init_arrays(progress_callback)
self._flightmodes = None

def _rewind(self):
Expand All @@ -1498,7 +1500,8 @@ def rewind(self):

def close(self):
super(mavmmaplog, self).close()
self.data_map.close()
if self.data_map is not None:
self.data_map.close()

def init_arrays(self, progress_callback=None):
'''initialise arrays for fast recv_match()'''
Expand Down Expand Up @@ -1618,6 +1621,8 @@ def init_arrays(self, progress_callback=None):

def skip_to_type(self, type):
'''skip fwd to next msg matching given type set'''
if self.data_map is None:
return
if self.type_nums is None:
# always add some key msg types so we can track flightmode, params etc
type = type.copy()
Expand Down

0 comments on commit 1b02514

Please sign in to comment.