Skip to content

Commit a7b9b1f

Browse files
committed
Trap possible divide-by-zero in getNavigationFrequency
1 parent 852d5a2 commit a7b9b1f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15978,6 +15978,15 @@ uint8_t SFE_UBLOX_GNSS::getNavigationFrequency(uint16_t maxWait)
1597815978

1597915979
uint16_t measurementRate = packetUBXCFGRATE->data.measRate;
1598015980

15981+
if (measurementRate == 0)
15982+
{
15983+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
15984+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
15985+
_debugSerial->println(F("getNavigationFrequency: zero measRate!"));
15986+
#endif
15987+
return(0); // Avoid divide-by-zero error
15988+
}
15989+
1598115990
measurementRate = 1000 / measurementRate; // This may return an int when it's a float, but I'd rather not return 4 bytes
1598215991
return (measurementRate);
1598315992
}

0 commit comments

Comments
 (0)