[Cleanup] Misc code cleanup + add comments from PVS Studio

This commit is contained in:
TD-er
2023-09-15 17:10:48 +02:00
parent 922ad76e5e
commit 9cd8bbf8ba
10 changed files with 87 additions and 117 deletions
+2
View File
@@ -401,6 +401,8 @@ void PZEM004Tv30::setCRC(uint8_t *buf, uint16_t len){
}
// FIXME TD-er: Should consider using ModbusRTU_struct::ModRTU_CRC (crcTable alone: 512 bytes, ModRTU_CRC: 56 bytes)
/*! * PZEM004Tv30::CRC16 *
* Calculate the CRC16-Modbus for a buffer
* Based on https://www.modbustools.com/modbus_crc16.html *
+1
View File
@@ -1161,6 +1161,7 @@ float readMax31856(struct EventStruct *event)
if (loglevelActiveFor(LOG_LEVEL_DEBUG_MORE))
{
// FIXME TD-er: Part of expression is always false (sr == 0)
const bool faultResolved = (P039_data->sensorFault) && (sr == 0);
if ((P039_data->sensorFault) || faultResolved) {
+73 -92
View File
@@ -255,9 +255,6 @@ void timeToStrip(uint8_t hours, uint8_t minutes)
//show hours
switch (hours) {
case 0:
pushTWELVE();
break;
case 1:
pushONE();
break;
@@ -291,6 +288,7 @@ void timeToStrip(uint8_t hours, uint8_t minutes)
case 11:
pushELEVEN();
break;
case 0:
case 12:
pushTWELVE();
break;
@@ -301,6 +299,13 @@ void timeToStrip(uint8_t hours, uint8_t minutes)
}
}
void pushToStrip(const int* ids, int count) {
for (size_t i = 0; i < count; ++i) {
pushToStrip(ids[i]);
}
}
void pushM_ONE() {
pushToStrip(0);
}
@@ -314,134 +319,110 @@ void pushM_FOUR() {
pushToStrip(113);
}
void pushIT_IS() {
pushToStrip(1);
pushToStrip(2);
pushToStrip(3);
pushToStrip(5);
pushToStrip(6);
constexpr int ids[] = {1, 2, 3, 5, 6};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushAFTER() {
pushToStrip(36);
pushToStrip(37);
pushToStrip(38);
pushToStrip(39);
constexpr int ids[] = {36, 37, 38, 39};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushQUATER() {
pushToStrip(30);
pushToStrip(31);
pushToStrip(32);
pushToStrip(33);
pushToStrip(34);
constexpr int ids[] = {30, 31, 32, 33, 34};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushFOR() {
pushToStrip(41);
pushToStrip(42);
pushToStrip(43);
pushToStrip(44);
constexpr int ids[] = {41, 42, 43, 44};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushHALF() {
pushToStrip(50);
pushToStrip(51);
pushToStrip(52);
pushToStrip(53);
constexpr int ids[] = {50, 51, 52, 53};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushONE() {
pushToStrip(63);
pushToStrip(64);
pushToStrip(65);
constexpr int ids[] = {63, 64, 65};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushTWO() {
pushToStrip(64);
pushToStrip(65);
pushToStrip(66);
pushToStrip(67);
constexpr int ids[] = {64, 65, 66, 67};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushTHREE() {
pushToStrip(109);
pushToStrip(110);
pushToStrip(111);
pushToStrip(112);
constexpr int ids[] = {109, 110, 111, 112};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushFOUR() {
pushToStrip(57);
pushToStrip(58);
pushToStrip(59);
pushToStrip(60);
constexpr int ids[] = {57, 58, 59, 60};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushFIVE1() {
pushToStrip(8);
pushToStrip(9);
pushToStrip(10);
pushToStrip(11);
constexpr int ids[] = {8, 9, 10, 11};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushFIVE2() {
pushToStrip(92);
pushToStrip(93);
pushToStrip(94);
pushToStrip(95);
constexpr int ids[] = {92, 93, 94, 95};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushSIX() {
pushToStrip(69);
pushToStrip(88);
pushToStrip(91);
constexpr int ids[] = {69, 88, 91};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushSEVEN() {
pushToStrip(69);
pushToStrip(70);
pushToStrip(71);
pushToStrip(72);
pushToStrip(73);
constexpr int ids[] = {69, 70, 71, 72, 73};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushEIGHT() {
pushToStrip(97);
pushToStrip(98);
pushToStrip(99);
pushToStrip(100);
constexpr int ids[] = {97, 98, 99, 100};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushNINE() {
pushToStrip(73);
pushToStrip(74);
pushToStrip(75);
pushToStrip(76);
pushToStrip(77);
constexpr int ids[] = {73, 74, 75, 76, 77};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushTEN() {
pushToStrip(54);
pushToStrip(59);
pushToStrip(76);
pushToStrip(81);
constexpr int ids[] = {54, 59, 76, 81};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushTEN1() {
pushToStrip(25);
pushToStrip(26);
pushToStrip(27);
pushToStrip(28);
constexpr int ids[] = {25, 26, 27, 28};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushELEVEN() {
pushToStrip(107);
pushToStrip(108);
pushToStrip(109);
constexpr int ids[] = {107, 108, 109};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushTWELVE() {
pushToStrip(82);
pushToStrip(83);
pushToStrip(84);
pushToStrip(85);
pushToStrip(86);
pushToStrip(87);
constexpr int ids[] = {82, 83, 84, 85, 86, 87};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushTWENTY() {
pushToStrip(16);
pushToStrip(17);
pushToStrip(18);
pushToStrip(19);
pushToStrip(20);
pushToStrip(21);
pushToStrip(22);
constexpr int ids[] = {16, 17, 18, 19, 20, 21, 22};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
void pushHOURE() {
pushToStrip(102);
pushToStrip(103);
pushToStrip(104);
constexpr int ids[] = {102,103,104};
constexpr int count = NR_ELEMENTS(ids);
pushToStrip(ids, count);
}
#endif // USES_P041
-10
View File
@@ -74,17 +74,7 @@ boolean Plugin_051(uint8_t function, struct EventStruct *event, String& string)
# endif // if FEATURE_I2C_GET_ADDRESS
case PLUGIN_WEBFORM_LOAD:
{
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
success = true;
break;
}
case PLUGIN_INIT:
{
success = true;
+2 -1
View File
@@ -393,7 +393,8 @@ boolean Plugin_075(uint8_t function, struct EventStruct *event, String& string)
}
__buffer[i] = 0x00;
// FIXME TD-er: (PVS Studio) A part of conditional expression is always false: (0xFF == __buffer[4]). The value range of char type: [-128, 127].
if ((0xFF == __buffer[4]) && (0xFF == __buffer[5]) && (0xFF == __buffer[6])) {
UserVar[event->BaseVarIndex] = (__buffer[1] * 256) + __buffer[2] + TOUCH_BASE;
UserVar[event->BaseVarIndex + 1] = __buffer[3];
+2 -2
View File
@@ -236,9 +236,9 @@ boolean Plugin_078(uint8_t function, struct EventStruct *event, String& string)
}
if (Plugin_078_ESPEasySerial->setRS485Mode(P078_DEPIN, P078_GET_FLAG_COLL_DETECT)) {
Plugin_078_SDM = new SDM(*Plugin_078_ESPEasySerial, baudrate);
Plugin_078_SDM = new (std::nothrow) SDM(*Plugin_078_ESPEasySerial, baudrate);
} else {
Plugin_078_SDM = new SDM(*Plugin_078_ESPEasySerial, baudrate, P078_DEPIN);
Plugin_078_SDM = new (std::nothrow) SDM(*Plugin_078_ESPEasySerial, baudrate, P078_DEPIN);
}
if (Plugin_078_SDM != nullptr) {
+2
View File
@@ -46,6 +46,8 @@
#include <HeatpumpIRFactory.h>
#include "ESPEasy-Globals.h"
IRSenderIRremoteESP8266 *Plugin_088_irSender = nullptr;
int panasonicCKPTimer = 0;
-7
View File
@@ -41,13 +41,6 @@ bool LogStruct::getNext(bool& logLinesAvailable, unsigned long& timestamp, Strin
return true;
}
bool LogStruct::isEmpty() const {
return !is_full && (write_idx == read_idx);
}
bool LogStruct::isFull() const {
return is_full;
}
bool LogStruct::logActiveRead() {
clearExpiredEntries();
+4 -2
View File
@@ -42,9 +42,11 @@ struct LogStruct {
// Returns whether a line was retrieved.
bool getNext(bool& logLinesAvailable, unsigned long& timestamp, String& message, uint8_t& loglevel);
bool isEmpty() const;
bool isEmpty() const {
return !is_full && (write_idx == read_idx);
}
bool isFull() const;
bool isFull() const { return is_full; }
bool logActiveRead();
+1 -3
View File
@@ -18,9 +18,7 @@
boolean ipLessEqual(const IPAddress& ip, const IPAddress& high)
{
unsigned long u_ip = ((unsigned long )ip[0] << 24) | ((unsigned long )ip[1] << 16) | ((unsigned long )ip[2] << 8) | ip[3];
unsigned long u_high = ((unsigned long )high[0] << 24) | ((unsigned long )high[1] << 16) | ((unsigned long )high[2] << 8) | high[3];
return u_ip <= u_high;
return ip.v4() <= high.v4();
}
boolean ipInRange(const IPAddress& ip, const IPAddress& low, const IPAddress& high)