Skip to content

Commit 1666dae

Browse files
authored
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!
1 parent 8d7ea10 commit 1666dae

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/NMEA_parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ bool Adafruit_GPS::parseTime(char *p) {
785785
char *dec = strchr(p, '.');
786786
char *comstar = min(strchr(p, ','), strchr(p, '*'));
787787
if (dec != NULL && comstar != NULL && dec < comstar)
788-
milliseconds = atof(p) * 1000;
788+
milliseconds = atof(dec) * 1000;
789789
else
790790
milliseconds = 0;
791791
lastTime = sentTime;

0 commit comments

Comments
 (0)