From d1d74165f696534dbb3884ab3d52fb952e2ec282 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Fri, 21 May 2021 13:53:58 -1000 Subject: [PATCH] Check freq != 0 in PWMSpindle to prevent div-by-0 crashes --- Grbl_Esp32/src/Spindles/PWMSpindle.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp index feddd629..3ad3b6ba 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp @@ -225,6 +225,9 @@ namespace Spindles { */ uint8_t PWM::calc_pwm_precision(uint32_t freq) { uint8_t precision = 0; + if (freq == 0) { + return precision; + } // increase the precision (bits) until it exceeds allow by frequency the max or is 16 while ((1 << precision) < (uint32_t)(80000000 / freq) && precision <= 16) {