From 851f11dcdde20f717bdef8862aaa9b755787858f Mon Sep 17 00:00:00 2001 From: stefanbode Date: Thu, 15 Aug 2024 10:08:54 +0200 Subject: [PATCH] fix potential overflow on uptime (#21965) * fix potential overflow * fix potential overflow * fix potential overflow * fix potential overflow --- tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino | 10 ++++------ tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino | 11 +++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino index 2a028bb97..d15bf81e9 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_esp32_shutter.ino @@ -213,14 +213,12 @@ void ShutterAllowPreStartProcedure(uint8_t i) { // Prestart allow e.g. to release a LOCK or something else before the movement start // Anyway, as long var1 != 99 this is skipped (luckily) #ifdef USE_RULES - uint32_t uptime_Local = 0; AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start? var%d <99>=<%s>, max10s?"),i + 1, rules_vars[i]); - uptime_Local = TasmotaGlobal.uptime; - while (uptime_Local + 10 > TasmotaGlobal.uptime - && (String)rules_vars[i] == "99") { - loop(); + // wait for response from rules + uint32_t start_time = millis(); + while (TimePassedSince(start_time) < 10000 && (String)rules_vars[i] == "99") { + delay(1); } - //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start. Done")); #endif // USE_RULES } diff --git a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino index 776f08a74..6ad2ed327 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_27_shutter.ino @@ -731,13 +731,12 @@ void ShutterAllowPreStartProcedure(uint8_t i) { // What PreStartProcedure do you want to execute here? // Anyway, as long var1 != 99 this is skipped (luckily) #ifdef USE_RULES - uint32_t uptime_Local=0; - AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start? var%d <99>=<%s>, max10s?"),i+1, rules_vars[i]); - uptime_Local = TasmotaGlobal.uptime; - while (uptime_Local+10 > TasmotaGlobal.uptime && (String)rules_vars[i] == "99") { - loop(); + AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start? var%d <99>=<%s>, max10s?"),i + 1, rules_vars[i]); + // wait for response from rules + uint32_t start_time = millis(); + while (TimePassedSince(start_time) < 10000 && (String)rules_vars[i] == "99") { + delay(1); } - //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start. Done")); #endif // USE_RULES }