Check for empty sensors in getFailSafePercent
Add an early return to DbusPidZone::getFailSafePercent() when
_failSafeSensors is empty.
This prevents calling std::max_element on an empty container and avoids
undefined behavior.
Motivation:
With offline-failsafe-pwm enabled, _failSafeSensors can be empty during
a control-loop reload or shutdown.
In that case, getFailSafePercent() yielded undefined values that
resolved to 0% PWM and risking an overtemperature.
This patch ensures a valid fallback percent is always returned.
Change-Id: Ic53c6771a71114a192f4a73fbde599d994c1567b
Signed-off-by: Eric Yang <eric.yang.wiwynn@gmail.com>
diff --git a/pid/zone.cpp b/pid/zone.cpp
index 6402c79..f8272bf 100644
--- a/pid/zone.cpp
+++ b/pid/zone.cpp
@@ -190,6 +190,11 @@
double DbusPidZone::getFailSafePercent(void)
{
+ if (_failSafeSensors.empty())
+ {
+ return _zoneFailSafePercent;
+ }
+
FailSafeSensorsMap::iterator maxData = std::max_element(
_failSafeSensors.begin(), _failSafeSensors.end(),
[](const FailSafeSensorPair firstData,