[PVS Studio] Fix some warnings made by PVS Studio.

This commit is contained in:
TD-er
2021-10-21 16:00:43 +02:00
parent c86dcb3022
commit 7d2788643e
9 changed files with 42 additions and 39 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ bool CPlugin_001(CPlugin::Function function, struct EventStruct *event, String&
url += event->idx;
url += F("&switchcmd=");
if (UserVar[event->BaseVarIndex] == 0) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) {
url += F("Off");
} else {
if (sensorType == Sensor_VType::SENSOR_TYPE_SWITCH) {
+2 -2
View File
@@ -249,7 +249,7 @@ boolean Plugin_013(uint8_t function, struct EventStruct *even
log += formatUserVarNoCheck(event->TaskIndex, 0);
log += (measuringUnit == UNIT_CM) ? F(" cm ") : F(" inch ");
if (value == NO_ECHO)
if (essentiallyEqual(value, NO_ECHO))
{
log += F(" Error: ");
log += Plugin_013_getErrorStatusString(event->TaskIndex);
@@ -271,7 +271,7 @@ boolean Plugin_013(uint8_t function, struct EventStruct *even
uint8_t state = 0;
float value = Plugin_013_read(event->TaskIndex);
if ((value != NO_ECHO) && (value < threshold)) {
if (!essentiallyEqual(value, NO_ECHO) && definitelyLessThan(value, threshold)) {
state = 1;
}
+11 -11
View File
@@ -596,7 +596,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
return success;
}
if ((UserVar[event->BaseVarIndex] == 1) && (P036_data->disableFrameChangeCnt)) {
if ((essentiallyEqual(UserVar[event->BaseVarIndex], 1.0f)) && (P036_data->disableFrameChangeCnt)) {
// display is on
// disableFrameChangeCnt==0 enables next page change after JumpToPage
P036_data->disableFrameChangeCnt--;
@@ -606,7 +606,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
if ((validGpio(CONFIG_PIN3)) && P036_data->ButtonState)
{
if (bitRead(P036_FLAGS_0, P036_FLAG_STEP_PAGES_BUTTON) && (UserVar[event->BaseVarIndex] == 1)) { // Bit 19 When display already on, switch to next page when enabled
if (bitRead(P036_FLAGS_0, P036_FLAG_STEP_PAGES_BUTTON) && (essentiallyEqual(UserVar[event->BaseVarIndex], 1.0f))) { // Bit 19 When display already on, switch to next page when enabled
if (P036_data->ScrollingPages.Scrolling == 0) { // page scrolling not running -> switch to next page is allowed
P036_data->P036_JumpToPage(event, 0xFF); // Start to display the next page, function needs 65ms!
}
@@ -643,7 +643,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
#ifdef P036_SEND_EVENTS
uint8_t currentFrame = P036_data->currentFrameToDisplay;
#endif
if ((UserVar[event->BaseVarIndex] == 1) && (P036_data->ScrollingPages.Scrolling == 0)) {
if ((essentiallyEqual(UserVar[event->BaseVarIndex], 1.0f)) && (P036_data->ScrollingPages.Scrolling == 0)) {
// Display is on.
P036_data->display_scrolling_lines(); // line scrolling
}
@@ -701,7 +701,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
}
}
if (UserVar[event->BaseVarIndex] == 1) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 1.0f)) {
// Display is on.
P036_data->HeaderContent = static_cast<eHeaderContent>(get8BitFromUL(P036_FLAGS_0, P036_FLAG_HEADER)); // Bit15-8 HeaderContent
@@ -747,7 +747,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
#ifdef P036_SEND_EVENTS
uint8_t currentFrame = P036_data->currentFrameToDisplay;
#endif
if ((UserVar[event->BaseVarIndex] == 1) && P036_data->display_scroll_timer()) { // page scrolling only when the display is on
if ((essentiallyEqual(UserVar[event->BaseVarIndex], 1.0f)) && P036_data->display_scroll_timer()) { // page scrolling only when the display is on
Scheduler.setPluginTaskTimer(P36_PageScrollTimer, event->TaskIndex, event->Par1); // calls next page scrollng tick
}
#ifdef P036_SEND_EVENTS
@@ -870,7 +870,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
#ifdef P036_SEND_EVENTS
if (sendEvents) {
P036_SendEvent(event, P036_EVENT_CONTRAST, 0);
if (UserVar[event->BaseVarIndex] == 0) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) {
P036_SendEvent(event, P036_EVENT_DISPLAY, 1);
}
}
@@ -884,7 +884,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
#ifdef P036_SEND_EVENTS
if (sendEvents) {
P036_SendEvent(event, P036_EVENT_CONTRAST, 1);
if (UserVar[event->BaseVarIndex] == 0) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) {
P036_SendEvent(event, P036_EVENT_DISPLAY, 1);
}
}
@@ -898,7 +898,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
#ifdef P036_SEND_EVENTS
if (sendEvents) {
P036_SendEvent(event, P036_EVENT_CONTRAST, 2);
if (UserVar[event->BaseVarIndex] == 0) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) {
P036_SendEvent(event, P036_EVENT_DISPLAY, 1);
}
}
@@ -910,7 +910,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
{
success = true;
if (UserVar[event->BaseVarIndex] == 0) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) {
// display was OFF, turn it ON
P036_data->display->displayOn();
UserVar[event->BaseVarIndex] = 1; // Save the fact that the display is now ON
@@ -965,7 +965,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
#ifdef P036_SEND_EVENTS
uint8_t currentFrame = P036_data->currentFrameToDisplay;
#endif
if ((UserVar[event->BaseVarIndex] == 0) && !bitRead(P036_FLAGS_0, P036_FLAG_NODISPLAY_ONRECEIVE)) { // Bit 18 NoDisplayOnReceivedText
if ((essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) && !bitRead(P036_FLAGS_0, P036_FLAG_NODISPLAY_ONRECEIVE)) { // Bit 18 NoDisplayOnReceivedText
// display was OFF, turn it ON
P036_data->display->displayOn();
UserVar[event->BaseVarIndex] = 1; // Save the fact that the display is now ON
@@ -979,7 +979,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
#endif
}
if (UserVar[event->BaseVarIndex] == 1) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 1.0f)) {
uint8_t nextFrame = ceil((static_cast<float>(LineNo)) / P036_data->ScrollingPages.linesPerFrame) - 1; // next frame shows the new content,
// 0-based
P036_data->P036_JumpToPage(event, nextFrame); // Start to display the selected page,
@@ -33,6 +33,7 @@ C015_queue_element& C015_queue_element::operator=(C015_queue_element&& other) {
txt[i] = std::move(other.txt[i]);
vPin[i] = other.vPin[i];
}
return *this;
}
bool C015_queue_element::checkDone(bool succesfull) const {
@@ -3,6 +3,7 @@
#include "../DataStructs/ESPEasy_EventStruct.h"
#include "../Globals/Plugins.h"
#include "../Globals/RuntimeData.h"
#include "../Helpers/ESPEasy_math.h"
#ifdef USES_C016
@@ -62,7 +63,7 @@ bool C016_queue_element::isDuplicate(const C016_queue_element& other) const {
}
for (uint8_t i = 0; i < VARS_PER_TASK; ++i) {
if (other.values[i] != values[i]) {
if (!essentiallyEqual(other.values[i] , values[i])) {
return false;
}
}
+2 -2
View File
@@ -265,7 +265,7 @@ String serializeDomoticzJson(struct EventStruct *event)
json += ',';
json += to_json_object_value(F("command"), F("switchlight"));
if (UserVar[event->BaseVarIndex] == 0) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) {
json += ',';
json += to_json_object_value(F("switchcmd"), F("Off"));
}
@@ -278,7 +278,7 @@ String serializeDomoticzJson(struct EventStruct *event)
json += ',';
json += to_json_object_value(F("command"), F("switchlight"));
if (UserVar[event->BaseVarIndex] == 0) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 0.0f)) {
json += ',';
json += to_json_object_value(F("switchcmd"), F("Off"));
}
+1 -1
View File
@@ -1035,7 +1035,7 @@ void P036_data_struct::P036_DisplayPage(struct EventStruct *event)
int NFrames; // the number of frames
if (UserVar[event->BaseVarIndex] == 1) {
if (essentiallyEqual(UserVar[event->BaseVarIndex], 1.0f)) {
// Display is on.
ScrollingPages.Scrolling = 1; // page scrolling running -> no
// line scrolling allowed
+2 -1
View File
@@ -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 >= 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());
@@ -1182,6 +1182,7 @@ bool P104_data_struct::handlePluginWrite(taskIndex_t taskIndex,
}
# endif // ifdef P104_USE_BAR_GRAPH
// FIXME TD-er: success is always false here. Maybe this must be done outside the for-loop?
if (success) { // Reset the repeat timer
if (it->repeatDelay > -1) {
it->_repeatTimer = millis();
+20 -20
View File
@@ -307,27 +307,27 @@ struct P104_zone_struct {
P104_zone_struct(uint8_t _zone) : text(F("\"\"")), zone(_zone) {}
String text;
int32_t repeatDelay = -1;
uint32_t _repeatTimer;
uint16_t speed = 0u;
uint16_t pause = 0u;
int32_t repeatDelay = -1;
uint32_t _repeatTimer = 0u;
uint16_t speed = 0u;
uint16_t pause = 0u;
uint8_t zone;
uint8_t size = 0u;
uint8_t alignment = 0u;
uint8_t animationIn = 1u; // Doesn't allow 'None'
uint8_t animationOut = 0u;
uint8_t font = 0u;
uint8_t content = 0u;
uint8_t layout = 0u;
uint8_t size = 0u;
uint8_t alignment = 0u;
uint8_t animationIn = 1u; // Doesn't allow 'None'
uint8_t animationOut = 0u;
uint8_t font = 0u;
uint8_t content = 0u;
uint8_t layout = 0u;
uint8_t specialEffect = 0u;
uint8_t offset = 0u;
int8_t brightness = -1;
int8_t inverted = 0;
int8_t _lastChecked = -1;
uint8_t offset = 0u;
int8_t brightness = -1;
int8_t inverted = 0;
int8_t _lastChecked = -1;
# ifdef P104_USE_BAR_GRAPH
uint16_t _lower = 0u;
uint16_t _upper = 0u; // lower and upper pixel numbers
uint8_t _startModule = 0u; // starting module, end module is _startModule + size - 1
uint16_t _lower = 0u;
uint16_t _upper = 0u; // lower and upper pixel numbers
uint8_t _startModule = 0u; // starting module, end module is _startModule + size - 1
# endif // ifdef P104_USE_BAR_GRAPH
};
@@ -421,10 +421,10 @@ private:
int8_t expectedZones = -1;
int8_t previousZones = -1;
bool initialized = false;
bool flasher = false; // seconds passing flasher
bool flasher = false; // seconds passing flasher
// time/date stuff
char szTimeL[P104_MAX_MESG] = { 0 }; // dd-mm-yyyy hh:mm:ss\0
char szTimeL[P104_MAX_MESG] = { 0 }; // dd-mm-yyyy hh:mm:ss\0
char szTimeH[P104_MAX_MESG] = { 0 };
};