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!
This commit is contained in:
Ron Barry 2020-10-18 01:41:23 -07:00 committed by GitHub
parent 8d7ea109f1
commit 1666dae26b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -785,7 +785,7 @@ bool Adafruit_GPS::parseTime(char *p) {
char *dec = strchr(p, '.'); char *dec = strchr(p, '.');
char *comstar = min(strchr(p, ','), strchr(p, '*')); char *comstar = min(strchr(p, ','), strchr(p, '*'));
if (dec != NULL && comstar != NULL && dec < comstar) if (dec != NULL && comstar != NULL && dec < comstar)
milliseconds = atof(p) * 1000; milliseconds = atof(dec) * 1000;
else else
milliseconds = 0; milliseconds = 0;
lastTime = sentTime; lastTime = sentTime;