From 3232d0d59d00f7b7e4e62f6c4bb364fe4d4fd3b8 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 2 Dec 2017 18:58:40 -0500 Subject: [PATCH] better state validation --- firmware/controllers/math/engine_math.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index 683226a8ec..09823cdab8 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -30,9 +30,13 @@ void setFlatInjectorLag(float value DECLARE_ENGINE_PARAMETER_SUFFIX); * @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke * I guess this implementation would be faster than 'angle % engineCycle' */ -#define fixAngle(angle, msg) \ +#define fixAngle(angle, msg) \ { \ - assertAngleRange(angle, msg); \ + if (cisnan(angle)) { \ + firmwareError(CUSTOM_ERR_6516, "angle NaN %s", msg); \ + angle = 0; \ + } \ + assertAngleRange(angle, msg); \ float engineCycleDurationLocalCopy = ENGINE(engineCycle); \ /* todo: split this method into 'fixAngleUp' and 'fixAngleDown'*/ \ /* as a performance optimization?*/ \