From 1666dae26bbcd61119b61291a72c8fdacd5df1c5 Mon Sep 17 00:00:00 2001 From: Ron Barry Date: Sun, 18 Oct 2020 01:41:23 -0700 Subject: [PATCH] Fix issue with millisecond parsing. By calling atof() on p, we're converting the entire time string (101520.123 for 10:15:20am and 123 milliseconds) to a float, then multiplying by 1000 to get ms. This results in a value that overflows and exhibits all sorts of strange behavior as seconds and minutes turn over. It's clearly not what was intended. From the if statement wrapping the conversion, it is clear that the author intended to make the atof() conversion on the dec pointer, instead. Making this change actually does fix the parsing so that Adafruit_GPS' milliseconds property correctly matches the value in the NMEA sentence. You guys do great work. Thanks for everything! --- src/NMEA_parse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NMEA_parse.cpp b/src/NMEA_parse.cpp index eaa5bfd..ddf59eb 100644 --- a/src/NMEA_parse.cpp +++ b/src/NMEA_parse.cpp @@ -785,7 +785,7 @@ bool Adafruit_GPS::parseTime(char *p) { char *dec = strchr(p, '.'); char *comstar = min(strchr(p, ','), strchr(p, '*')); if (dec != NULL && comstar != NULL && dec < comstar) - milliseconds = atof(p) * 1000; + milliseconds = atof(dec) * 1000; else milliseconds = 0; lastTime = sentTime;