Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2021-05-01 21:28:26 +0300
committerDavid Crocker <dcrocker@eschertech.com>2021-05-01 21:28:26 +0300
commit2bf1b349faedfca7594bf6296a2dec6c36e95b82 (patch)
treee679611fdf399b83f6859ad83c989a640aeafc2a /src/Accelerometers
parent31e191242d78fb96a327f281d7acbf91ad8ba93c (diff)
Fix division by zero in accelerometer code
Diffstat (limited to 'src/Accelerometers')
-rw-r--r--src/Accelerometers/LIS3DH.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/Accelerometers/LIS3DH.cpp b/src/Accelerometers/LIS3DH.cpp
index d4e22502..121ddb1c 100644
--- a/src/Accelerometers/LIS3DH.cpp
+++ b/src/Accelerometers/LIS3DH.cpp
@@ -160,8 +160,10 @@ unsigned int LIS3DH::CollectData(const uint16_t **collectedData, uint16_t &dataR
*collectedData = reinterpret_cast<const uint16_t*>(dataBuffer);
overflowed = (fifoStatus & 0x40) != 0;
- dataRate = (totalNumRead == 0) ? 0
- : (totalNumRead * StepTimer::StepClockRate)/(lastInterruptTime - firstInterruptTime);
+ const uint32_t interval = lastInterruptTime - firstInterruptTime;
+ dataRate = (totalNumRead == 0 || interval == 0)
+ ? 0
+ : (totalNumRead * StepTimer::StepClockRate)/interval;
totalNumRead += numToRead;
}
return numToRead;