From e4e1d7b57d069f8d200656cce1456c09975ed0f8 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 14 Aug 2024 12:25:32 +1000 Subject: [PATCH] mavutil: correct processing of zero-length logs can't mmap a zero-length file --- mavutil.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mavutil.py b/mavutil.py index 7cb26e526..bbb5d6993 100644 --- a/mavutil.py +++ b/mavutil.py @@ -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): @@ -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()''' @@ -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()