From 7e67765fc90c1c6fb8ccf4f1d5acead288ab46e5 Mon Sep 17 00:00:00 2001 From: TD-er Date: Thu, 21 Oct 2021 09:59:29 +0200 Subject: [PATCH] [PVS Studio] Test using ESP32 max build + some suggested fixes --- platformio_special_envs.ini | 16 ++++++++++++++++ src/_C008.ino | 2 +- src/_C010.ino | 2 +- src/_C011.ino | 4 ++-- src/_C016.ino | 4 ++-- src/_C018.ino | 2 +- src/_P003_Pulse.ino | 12 +++++------- src/src/Commands/Blynk.cpp | 2 +- src/src/Commands/MQTT.cpp | 4 ++-- .../ControllerDelayHandlerStruct.h | 2 +- src/src/ControllerQueue/DelayQueueElements.cpp | 2 +- src/src/DataStructs/SettingsStruct.h | 2 +- src/src/ESPEasyCore/Controller.cpp | 6 +++--- src/src/Helpers/ESPEasy_FactoryDefault.cpp | 2 +- src/src/Helpers/ESPEasy_Storage.cpp | 2 +- src/src/PluginStructs/P104_data_struct.cpp | 2 +- src/src/WebServer/ControllerPage.cpp | 6 +++--- 17 files changed, 43 insertions(+), 29 deletions(-) diff --git a/platformio_special_envs.ini b/platformio_special_envs.ini index 7efd4078e..68220a5b2 100644 --- a/platformio_special_envs.ini +++ b/platformio_special_envs.ini @@ -55,6 +55,22 @@ board = esp32dev extra_scripts = ${esp32_common.extra_scripts} pre:tools/pio/pre_custom_esp32.py +[env:spec_debug_max_ESP32_16M8M] +extends = esp32_common, debug_pio +lib_ignore = ${esp32_always.lib_ignore}, ESP32_ping +lib_deps = ${esp32_common.lib_deps}, VL53L0X +board_upload.maximum_size = 4194304 +build_flags = ${esp32_common.build_flags} + ${debug_pio.build_flags} + -DFEATURE_ARDUINO_OTA + -DPLUGIN_BUILD_MAX_ESP32 + -DPLUGIN_BUILD_IR_EXTENDED +; TODO: To enable PS-RAM Support needs more build flags than these 2, for now define ESP32_ENABLE_PSRAM is used to en/disable detecting PS-Ram size on Info page +; -DBOARD_HAS_PSRAM // both flags already enabled for Lolin D32 Pro board by PlatformIO +; -mfix-esp32-psram-cache-issue +board = lolin_d32_pro + + diff --git a/src/_C008.ino b/src/_C008.ino index cb88f6153..1a8e63cf2 100644 --- a/src/_C008.ino +++ b/src/_C008.ino @@ -63,7 +63,7 @@ bool CPlugin_008(CPlugin::Function function, struct EventStruct *event, String& String pubname; { // Place the ControllerSettings in a scope to free the memory as soon as we got all relevant information. - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addLog(LOG_LEVEL_ERROR, F("C008 : Generic HTTP - Cannot send, out of RAM")); diff --git a/src/_C010.ino b/src/_C010.ino index cbe032d70..ecb7077b7 100644 --- a/src/_C010.ino +++ b/src/_C010.ino @@ -69,7 +69,7 @@ bool CPlugin_010(CPlugin::Function function, struct EventStruct *event, String& { String pubname; { - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { break; diff --git a/src/_C011.ino b/src/_C011.ino index 107db5d88..f768f5603 100644 --- a/src/_C011.ino +++ b/src/_C011.ino @@ -59,7 +59,7 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String& case CPlugin::Function::CPLUGIN_INIT: { { - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (AllocatedControllerSettings()) { LoadControllerSettings(event->ControllerIndex, ControllerSettings); @@ -114,7 +114,7 @@ bool CPlugin_011(CPlugin::Function function, struct EventStruct *event, String& } { // Place in scope to delete ControllerSettings as soon as it is no longer needed - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addHtmlError(F("Out of memory, cannot load page")); diff --git a/src/_C016.ino b/src/_C016.ino index d7bb18c80..3abb1da72 100644 --- a/src/_C016.ino +++ b/src/_C016.ino @@ -74,7 +74,7 @@ bool CPlugin_016(CPlugin::Function function, struct EventStruct *event, String& case CPlugin::Function::CPLUGIN_INIT: { { - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (AllocatedControllerSettings()) { LoadControllerSettings(event->ControllerIndex, ControllerSettings); @@ -124,7 +124,7 @@ bool CPlugin_016(CPlugin::Function function, struct EventStruct *event, String& break; } - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 LoadControllerSettings(event->ControllerIndex, ControllerSettings); success = C016_DelayHandler->addToQueue(std::move(element)); Scheduler.scheduleNextDelayQueue(ESPEasy_Scheduler::IntervalTimer_e::TIMER_C016_DELAY_QUEUE, diff --git a/src/_C018.ino b/src/_C018.ino index 1925dfcad..c3b944d6a 100644 --- a/src/_C018.ino +++ b/src/_C018.ino @@ -837,7 +837,7 @@ bool C018_init(struct EventStruct *event) { } { // Allocate ControllerSettings object in a scope, so we can destruct it as soon as possible. - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { return false; diff --git a/src/_P003_Pulse.ino b/src/_P003_Pulse.ino index 860621c58..3fa238594 100644 --- a/src/_P003_Pulse.ino +++ b/src/_P003_Pulse.ino @@ -159,6 +159,7 @@ boolean Plugin_003(uint8_t function, struct EventStruct *event, String& string) switch (PCONFIG(P003_IDX_COUNTERTYPE)) { case P003_CT_INDEX_COUNTER: + case P003_CT_INDEX_COUNTER_TOTAL: { P003_data->pulseHelper.setPulseCounter(UserVar[event->BaseVarIndex + P003_IDX_pulseCounter]); break; @@ -173,16 +174,13 @@ boolean Plugin_003(uint8_t function, struct EventStruct *event, String& string) { break; } - case P003_CT_INDEX_COUNTER_TOTAL: - { - P003_data->pulseHelper.setPulseCounter(UserVar[event->BaseVarIndex + P003_IDX_pulseCounter]); - break; - } } if (loglevelActiveFor(LOG_LEVEL_INFO)) { - String log; log.reserve(20); - log = F("INIT : PulsePin: "); log += Settings.TaskDevicePin1[event->TaskIndex]; + String log; + log.reserve(20); + log = F("INIT : PulsePin: "); + log += Settings.TaskDevicePin1[event->TaskIndex]; addLog(LOG_LEVEL_INFO, log); } diff --git a/src/src/Commands/Blynk.cpp b/src/src/Commands/Blynk.cpp index 952c0b430..fa1c3ec76 100644 --- a/src/src/Commands/Blynk.cpp +++ b/src/src/Commands/Blynk.cpp @@ -73,7 +73,7 @@ bool Blynk_get(const String& command, controllerIndex_t controllerIndex, float * { // Place ControllerSettings in its own scope, as it is quite big. - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addLog(LOG_LEVEL_ERROR, F("Blynk : Cannot run GET, out of RAM")); return false; diff --git a/src/src/Commands/MQTT.cpp b/src/src/Commands/MQTT.cpp index 7be3cc369..79c81a225 100644 --- a/src/src/Commands/MQTT.cpp +++ b/src/src/Commands/MQTT.cpp @@ -40,7 +40,7 @@ const __FlashStringHelper * Command_MQTT_Publish(struct EventStruct *event, cons bool mqtt_retainFlag; { // Place the ControllerSettings in a scope to free the memory as soon as we got all relevant information. - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addLog(LOG_LEVEL_ERROR, F("MQTT : Cannot publish, out of RAM")); return F("MQTT : Cannot publish, out of RAM"); @@ -93,7 +93,7 @@ const __FlashStringHelper * Command_MQTT_Subscribe(struct EventStruct *event, co bool mqtt_retainFlag; { // Place the ControllerSettings in a scope to free the memory as soon as we got all relevant information. - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addLog(LOG_LEVEL_ERROR, F("MQTT : Cannot subscribe, out of RAM")); return F("MQTT : Cannot subscribe, out of RAM"); diff --git a/src/src/ControllerQueue/ControllerDelayHandlerStruct.h b/src/src/ControllerQueue/ControllerDelayHandlerStruct.h index f034fbe21..24d351125 100644 --- a/src/src/ControllerQueue/ControllerDelayHandlerStruct.h +++ b/src/src/ControllerQueue/ControllerDelayHandlerStruct.h @@ -295,7 +295,7 @@ struct ControllerDelayHandlerStruct { if (C##NNN####M##_DelayHandler == nullptr) return; \ C##NNN####M##_queue_element *element(C##NNN####M##_DelayHandler->getNext()); \ if (element == nullptr) return; \ - MakeControllerSettings(ControllerSettings); \ + MakeControllerSettings(ControllerSettings); \ bool ready = true; \ if (!AllocatedControllerSettings()) { \ ready = false; \ diff --git a/src/src/ControllerQueue/DelayQueueElements.cpp b/src/src/ControllerQueue/DelayQueueElements.cpp index 371466a7c..d7d99aca4 100644 --- a/src/src/ControllerQueue/DelayQueueElements.cpp +++ b/src/src/ControllerQueue/DelayQueueElements.cpp @@ -9,7 +9,7 @@ ControllerDelayHandlerStruct *MQTTDelayHandler = nullptr; bool init_mqtt_delay_queue(controllerIndex_t ControllerIndex, String& pubname, bool& retainFlag) { - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { return false; } diff --git a/src/src/DataStructs/SettingsStruct.h b/src/src/DataStructs/SettingsStruct.h index 4aaf18ae7..26d95148c 100644 --- a/src/src/DataStructs/SettingsStruct.h +++ b/src/src/DataStructs/SettingsStruct.h @@ -326,7 +326,7 @@ class SettingsStruct_tmpl int8_t SPI_SCLK_pin = -1; int8_t SPI_MISO_pin = -1; int8_t SPI_MOSI_pin = -1; - int8_t alignmentFiller0; // Should be reused, just added to keep up with alignment + int8_t alignmentFiller0 = 0; // Should be reused, just added to keep up with alignment }; /* diff --git a/src/src/ESPEasyCore/Controller.cpp b/src/src/ESPEasyCore/Controller.cpp index 6d712c15f..2bbca4d45 100644 --- a/src/src/ESPEasyCore/Controller.cpp +++ b/src/src/ESPEasyCore/Controller.cpp @@ -172,7 +172,7 @@ void MQTTDisconnect() bool MQTTConnect(controllerIndex_t controller_idx) { ++mqtt_reconnect_count; - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addLog(LOG_LEVEL_ERROR, F("MQTT : Cannot connect, out of RAM")); @@ -319,7 +319,7 @@ bool MQTTCheck(controllerIndex_t controller_idx) String LWTTopic, LWTMessageConnect; bool willRetain = false; { - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addLog(LOG_LEVEL_ERROR, F("MQTT : Cannot check, out of RAM")); @@ -538,7 +538,7 @@ void MQTTStatus(struct EventStruct *event, const String& status) bool mqtt_retainFlag; { // Place the ControllerSettings in a scope to free the memory as soon as we got all relevant information. - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addLog(LOG_LEVEL_ERROR, F("MQTT : Cannot send status, out of RAM")); diff --git a/src/src/Helpers/ESPEasy_FactoryDefault.cpp b/src/src/Helpers/ESPEasy_FactoryDefault.cpp index a28381707..1545621dc 100644 --- a/src/src/Helpers/ESPEasy_FactoryDefault.cpp +++ b/src/src/Helpers/ESPEasy_FactoryDefault.cpp @@ -234,7 +234,7 @@ void ResetFactory() #if DEFAULT_CONTROLLER { // Place in a scope to have its memory freed ASAP - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (AllocatedControllerSettings()) { safe_strncpy(ControllerSettings.Subscribe, F(DEFAULT_SUB), sizeof(ControllerSettings.Subscribe)); diff --git a/src/src/Helpers/ESPEasy_Storage.cpp b/src/src/Helpers/ESPEasy_Storage.cpp index bc25b838a..5172d926a 100644 --- a/src/src/Helpers/ESPEasy_Storage.cpp +++ b/src/src/Helpers/ESPEasy_Storage.cpp @@ -219,7 +219,7 @@ String BuildFixes() #ifdef USES_MQTT controllerIndex_t controller_idx = firstEnabledMQTT_ControllerIndex(); if (validControllerIndex(controller_idx)) { - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (AllocatedControllerSettings()) { LoadControllerSettings(controller_idx, ControllerSettings); diff --git a/src/src/PluginStructs/P104_data_struct.cpp b/src/src/PluginStructs/P104_data_struct.cpp index cb3f31ad6..e961894ba 100644 --- a/src/src/PluginStructs/P104_data_struct.cpp +++ b/src/src/PluginStructs/P104_data_struct.cpp @@ -505,7 +505,7 @@ void P104_data_struct::configureZones() { void P104_data_struct::displayOneZoneText(uint8_t zone, const P104_zone_struct& zstruct, const String & text) { - if ((nullptr == P) || (zone < 0) || (zone > P104_MAX_ZONES)) { return; } // double check + if ((nullptr == P) || (zone < 0) || (zone >= P104_MAX_ZONES)) { return; } // double check sZoneInitial[zone].reserve(text.length()); sZoneInitial[zone] = text; // Keep the original string for future use sZoneBuffers[zone].reserve(text.length()); diff --git a/src/src/WebServer/ControllerPage.cpp b/src/src/WebServer/ControllerPage.cpp index 1e2d20641..95d885029 100644 --- a/src/src/WebServer/ControllerPage.cpp +++ b/src/src/WebServer/ControllerPage.cpp @@ -50,7 +50,7 @@ void handle_controllers() { bool mustCallCpluginSave = false; { // Place in a scope to free ControllerSettings memory ASAP - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addHtmlError(F("Not enough free memory to save settings")); } else { @@ -198,7 +198,7 @@ void handle_controllers_ShowAllControllersTable() html_table_header(F("Host")); html_table_header(F("Port")); - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (AllocatedControllerSettings()) { for (controllerIndex_t x = 0; x < CONTROLLER_MAX; x++) { @@ -296,7 +296,7 @@ void handle_controllers_ControllerSettingsPage(controllerIndex_t controllerindex if (Settings.Protocol[controllerindex]) { { - MakeControllerSettings(ControllerSettings); + MakeControllerSettings(ControllerSettings); //-V522 if (!AllocatedControllerSettings()) { addHtmlError(F("Out of memory, cannot load page")); } else {