[Git][NTPsec/ntpsec][master] 2 commits: Fix issue where count_used_satellites checked before it is initialized.

Matt Selsky (@selsky) gitlab at mg.gitlab.com
Fri Apr 21 01:10:33 UTC 2023



Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
8364cab6 by James Browning at 2023-04-21T01:04:48+00:00
Fix issue where count_used_satellites checked before it is initialized.

- - - - -
a7ef828c by James Browning at 2023-04-21T01:04:48+00:00
ntploggps: Remove an arrow anti-pattern.

- - - - -


2 changed files:

- NEWS.adoc
- ntpclients/ntploggps.py


Changes:

=====================================
NEWS.adoc
=====================================
@@ -14,6 +14,8 @@ on user-visible changes.
 
 * Update license file names for REUSE compliance.
 
+* Fix ntploggps issue where count_used_satellites checked before it is initialized.
+
 * Print out OpenSSL version at configure time.
 
 * Enable debug symbols by default, with only an option to disable.


=====================================
ntpclients/ntploggps.py
=====================================
@@ -1,5 +1,7 @@
 #! @PYSHEBANG@
 # -*- coding: utf-8 -*-
+# Copyright the NTPsec project contributors
+# SPDX-License-Identifier: BSD-2-Clause
 
 """\
 usage: ntploggps [-h] [-o] [-l LOGFILE] [-v] [-V]
@@ -158,29 +160,32 @@ class GpsPoller(threading.Thread):
             if self.gpsd.read() == -1:
                 self.running = False
                 break
-            if hasattr(self.gpsd, "data"):
-                if self.gpsd.data.get("class", None) == "SKY":
-                    satellite_list = self.gpsd.data.get(
-                        "satellites", None
-                    )
-                    if satellite_list is not None:
-                        count_used_satellites = sum(
-                            map(lambda x: x.used, satellite_list)
-                        )
-                    time_dilution = self.gpsd.data.get("tdop", None)
-                    device_path = self.gpsd.data.get("device", None)
-                    if count_used_satellites is None:
-                        count_used_satellites = self.gpsd.data.get(
-                            "uSat", None
-                        )
-                    if None not in [
-                        count_used_satellites,
-                        time_dilution,
-                        device_path,
-                    ]:
-                        self.satellites_used = count_used_satellites
-                        self.tdop = time_dilution
-                        self.device = device_path
+            if not hasattr(self.gpsd, "data"):
+                continue
+            if self.gpsd.data.get("class", None) != "SKY":
+                continue
+            satellite_list = self.gpsd.data.get(
+                "satellites", None
+            )
+            count_used_satellites = None
+            if satellite_list is not None:
+                count_used_satellites = sum(
+                    map(lambda x: x.used, satellite_list)
+                )
+            time_dilution = self.gpsd.data.get("tdop", None)
+            device_path = self.gpsd.data.get("device", None)
+            if count_used_satellites is None:
+                count_used_satellites = self.gpsd.data.get(
+                    "uSat", None
+                )
+            if None not in [
+                count_used_satellites,
+                time_dilution,
+                device_path,
+            ]:
+                self.satellites_used = count_used_satellites
+                self.tdop = time_dilution
+                self.device = device_path
 
     @property
     def time(self):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/86bc7f9837134185d7a715dfc0fd8532804a9e1f...a7ef828c03ccc27bf94bad3b0b374fcc0e323388

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/86bc7f9837134185d7a715dfc0fd8532804a9e1f...a7ef828c03ccc27bf94bad3b0b374fcc0e323388
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20230421/26c80b48/attachment-0001.htm>


More information about the vc mailing list