Skip to content

Commit 8cea0af

Browse files
authored
Merge pull request letscontrolit#3697 from TD-er/bugfix/Fixes_core_300_pr
Fixes taken from 'core 3.0.0' PR
2 parents 167383a + 0332362 commit 8cea0af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+454
-192
lines changed

lib/Regexp/src/Regexp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ typedef class MatchState {
9696
unsigned int MatchStart = 0; // zero-relative offset of start of match
9797
unsigned int MatchLength = 0; // length of match
9898

99-
int level; /* total number of captures in array below (finished or unfinished) */
99+
int level = 0; /* total number of captures in array below (finished or unfinished) */
100100

101101
// capture addresses and lengths
102102
struct {
103-
const char *init;
104-
int len; // might be CAP_UNFINISHED or CAP_POSITION
103+
const char *init = nullptr;
104+
int len = 0; // might be CAP_UNFINISHED or CAP_POSITION
105105
} capture[MAXCAPTURES];
106106

107107
// add target string, null-terminated

src/_C013.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ void C013_SendUDPTaskInfo(byte destUnit, byte sourceTaskIndex, byte destTaskInde
101101
infoReply.destTaskIndex = destTaskIndex;
102102
infoReply.deviceNumber = pluginID;
103103
LoadTaskSettings(infoReply.sourceTaskIndex);
104-
strcpy(infoReply.taskName, getTaskDeviceName(infoReply.sourceTaskIndex).c_str());
104+
safe_strncpy(infoReply.taskName, getTaskDeviceName(infoReply.sourceTaskIndex), sizeof(infoReply.taskName));
105105

106106
for (byte x = 0; x < VARS_PER_TASK; x++) {
107-
strcpy(infoReply.ValueNames[x], ExtraTaskSettings.TaskDeviceValueNames[x]);
107+
safe_strncpy(infoReply.ValueNames[x], ExtraTaskSettings.TaskDeviceValueNames[x], sizeof(infoReply.ValueNames[x]));
108108
}
109109

110110
if (destUnit != 0)

src/_C018.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ private:
356356
}
357357

358358
void triggerAutobaud() {
359-
if ((C018_easySerial == nullptr) || (myLora == nullptr)) {}
359+
if ((C018_easySerial == nullptr) || (myLora == nullptr)) {
360+
return;
361+
}
360362
int retries = 2;
361363

362364
while (retries > 0 && !autobaud_success) {
@@ -896,7 +898,7 @@ bool C018_init(struct EventStruct *event) {
896898
return false;
897899
}
898900

899-
if (!C018_data->txUncnf("ESPeasy (TTN)", Port)) {
901+
if (!C018_data->txUncnf(F("ESPeasy (TTN)"), Port)) {
900902
return false;
901903
}
902904
return true;

src/_P036_FrameOLED.ino

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -804,20 +804,22 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
804804

805805
// calculate Pix length of new Content
806806
P036_data->display->setFont(P036_data->ScrollingPages.Font);
807-
uint16_t PixLength = P036_data->display->getStringWidth(String(P036_data->DisplayLinesV1[LineNo - 1].Content));
807+
uint16_t PixLength = P036_data->display->getStringWidth(P036_data->DisplayLinesV1[LineNo - 1].Content);
808808

809809
if (PixLength > 255) {
810810
String str_error = F("Pixel length of ");
811811
str_error += PixLength;
812812
str_error += F(" too long for line! Max. 255 pix!");
813813
addHtmlError(str_error);
814814

815-
int strlen = String(P036_data->DisplayLinesV1[LineNo - 1].Content).length();
816-
float fAvgPixPerChar = ((float)PixLength) / strlen;
817-
int iCharToRemove = ceil(((float)(PixLength - 255)) / fAvgPixPerChar);
815+
const int strlen = strnlen_P(P036_data->DisplayLinesV1[LineNo - 1].Content, sizeof(P036_data->DisplayLinesV1[LineNo - 1].Content));
816+
if (strlen > 0) {
817+
const float fAvgPixPerChar = ((float)PixLength) / strlen;
818+
const int iCharToRemove = ceil(((float)(PixLength - 255)) / fAvgPixPerChar);
818819

819-
// shorten string because OLED controller can not handle such long strings
820-
P036_data->DisplayLinesV1[LineNo - 1].Content[strlen - iCharToRemove] = 0;
820+
// shorten string because OLED controller can not handle such long strings
821+
P036_data->DisplayLinesV1[LineNo - 1].Content[strlen - iCharToRemove] = 0;
822+
}
821823
}
822824
P036_data->MaxFramesToDisplay = 0xff; // update frame count
823825

@@ -848,7 +850,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
848850
log += F(" Length:");
849851
log += P036_data->DisplayLinesV1[LineNo - 1].Content).length();
850852
log += F(" Pix: ");
851-
log += P036_data->display->getStringWidth(String(P036_data->DisplayLinesV1[LineNo - 1].Content));
853+
log += P036_data->display->getStringWidth(P036_data->DisplayLinesV1[LineNo - 1].Content);
852854
log += F(" Reserved:");
853855
log += P036_data->DisplayLinesV1[LineNo - 1].reserved;
854856
addLog(LOG_LEVEL_INFO, log);

src/_P039_Thermosensors.ino

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
// #endif
6767

6868

69-
#define MAX31865_RD_ADDRESS(n) (MAX31865_READ_ADDR_BASE + n)
70-
#define MAX31865_WR_ADDRESS(n) (MAX31865_WRITE_ADDR_BASE + n)
69+
#define MAX31865_RD_ADDRESS(n) (MAX31865_READ_ADDR_BASE + (n))
70+
#define MAX31865_WR_ADDRESS(n) (MAX31865_WRITE_ADDR_BASE + (n))
7171

7272
# define PLUGIN_039
7373
# define PLUGIN_ID_039 39
@@ -1189,6 +1189,9 @@ float readMax31856(struct EventStruct *event)
11891189
float readMax31865(struct EventStruct *event)
11901190
{
11911191
P039_data_struct *P039_data = static_cast<P039_data_struct *>(getPluginTaskData(event->TaskIndex));
1192+
if (P039_data == nullptr) {
1193+
return NAN;
1194+
}
11921195

11931196
uint8_t registers[MAX31865_NO_REG] = {0};
11941197
uint16_t rawValue = 0u;
@@ -1262,12 +1265,12 @@ float readMax31865(struct EventStruct *event)
12621265
//activate BIAS short before read, to reduce power consumption
12631266
change8BitRegister(CS_pin_no, (MAX31865_READ_ADDR_BASE + MAX31865_CONFIG),(MAX31865_WRITE_ADDR_BASE + MAX31865_CONFIG), MAX31865_SET_VBIAS_ON, P039_SET );
12641267

1265-
// save current timer for next calculation
1266-
P039_data->timer = millis();
1267-
12681268
// start time to follow up on BIAS activation before starting the conversion
12691269
// and start conversion sequence via TIMER API
12701270
if(nullptr != P039_data){
1271+
// save current timer for next calculation
1272+
P039_data->timer = millis();
1273+
12711274
// set next state to MAX31865_BIAS_ON_STATE
12721275

12731276
Scheduler.setPluginTaskTimer(MAX31865_BIAS_WAIT_TIME, event->TaskIndex, MAX31865_BIAS_ON_STATE);

src/_P042_Candle.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void type_Static_Light() {
512512
void type_Simple_Candle() {
513513
int r, g, b;
514514
if (Candle_color == ColorDefault) {
515-
r = 226, g = 042, b = 35; // Regular (orange) flame
515+
r = 226, g = 42, b = 35; // Regular (orange) flame
516516
//r = 158, g = 8, b = 148; // Purple flame
517517
//r = 74, g = 150, b = 12; // Green flame
518518
} else {

src/_P049_MHZ19.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ struct P049_data_struct : public PluginTaskData_base {
320320
unsigned long lastInitTimestamp = 0;
321321

322322
ESPeasySerial *easySerial = nullptr;
323-
byte mhzResp[9]; // 9 byte response buffer
323+
byte mhzResp[9] = {0}; // 9 byte response buffer
324324
// Default of the sensor is to run ABC
325325
bool ABC_Disable = false;
326326
bool ABC_MustApply = false;

src/_P062_MPR121_KeyPad.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ boolean Plugin_062(byte function, struct EventStruct *event, String& string)
161161
if (tbUseCalibration) {
162162
addFormCheckBox(F("Clear calibrationdata"), F("p062_clear_calibrate"), false);
163163
}
164-
} else {
165-
delete P062_data;
166164
}
165+
delete P062_data;
167166
}
168167
success = true;
169168
break;

src/_P073_7DGT.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,10 @@ void LogBufferContent(String prefix) {
436436
}
437437
}
438438

439-
int dotpos;
440-
uint8_t showbuffer[8];
439+
int dotpos = 0;
440+
uint8_t showbuffer[8] = {0};
441441
bool showperiods[8];
442-
byte spidata[2];
442+
byte spidata[2] = {0};
443443
uint8_t pin1, pin2, pin3;
444444
byte displayModel;
445445
byte output;

src/_P077_CSE7766.ino

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ struct P077_data_struct : public PluginTaskData_base {
155155

156156
// uint8_t cse_receive_flag = 0;
157157

158-
uint8_t serial_in_buffer[32];
158+
uint8_t serial_in_buffer[32] = {0};
159159
long voltage_cycle = 0;
160160
long current_cycle = 0;
161161
long power_cycle = 0;
@@ -168,9 +168,15 @@ struct P077_data_struct : public PluginTaskData_base {
168168
float energy_power = 0; // 123.1 W
169169

170170
// stats
171-
long t_max = 0, t_all = 0, t_pkt = 0, t_pkt_tmp = 0;
172-
uint16_t count_bytes = 0, count_max = 0, count_pkt = 0;
173-
uint8_t checksum = 0, adjustment = 0;
171+
long t_max = 0;
172+
long t_all = 0;
173+
long t_pkt = 0;
174+
long t_pkt_tmp = 0;
175+
uint16_t count_bytes = 0;
176+
uint16_t count_max = 0;
177+
uint16_t count_pkt = 0;
178+
uint8_t checksum = 0;
179+
uint8_t adjustment = 0;
174180
};
175181

176182

src/_P102_PZEM004Tv3.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# define P102_QUERY3 PCONFIG(5)
2828
# define P102_QUERY4 PCONFIG(6)
2929
# define P102_PZEM_FIRST PCONFIG(7)
30-
# define P102_PZEM_ATTEMPT PCONFIG(8)
30+
# define P102_PZEM_ATTEMPT PCONFIG_LONG(1)
3131

3232
# define P102_PZEM_mode_DFLT 0 // Read value
3333
# define P102_QUERY1_DFLT 0 // Voltage (V)

src/src/Commands/Common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ String Command_GetORSetString(struct EventStruct *event,
120120
serialPrintln();
121121
return return_result(event, result);
122122
}
123-
strcpy(target, TmpStr1.c_str());
123+
safe_strncpy(target, TmpStr1, len);
124124
}
125125
}
126126

src/src/Commands/GPIO.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ const __FlashStringHelper * Command_GPIO_Toggle(struct EventStruct *event, const
407407
log += F(" toggle: port#");
408408
log += event->Par1;
409409
log += F(": set to ");
410-
log += !state;
410+
log += static_cast<int>(!state);
411411
addLog(LOG_LEVEL_ERROR, log);
412412
SendStatusOnlyIfNeeded(event, SEARCH_PIN_STATE, key, log, 0);
413413

@@ -417,11 +417,9 @@ const __FlashStringHelper * Command_GPIO_Toggle(struct EventStruct *event, const
417417
case PIN_MODE_OFFLINE:
418418
logErrorGpioOffline(logPrefix, event->Par1);
419419
return return_command_failed();
420-
break;
421420
default:
422421
logErrorGpioNotOutput(logPrefix, event->Par1);
423422
return return_command_failed();
424-
break;
425423
}
426424
} else {
427425
logErrorGpioOutOfRange(logPrefix, event->Par1, Line);
@@ -667,7 +665,7 @@ range_pattern_helper_data range_pattern_helper_shared(pluginID_t plugin, struct
667665
data.isMask = !parseString(Line, 5).isEmpty();
668666

669667
if (data.isMask) {
670-
data.mask = event->Par4 & ((1 << data.numBytes * 8) - 1);
668+
data.mask = event->Par4 & ((1 << (data.numBytes * 8)) - 1);
671669
data.mask &= ((1 << data.numBits) - 1);
672670
data.mask = data.mask << data.deltaStart;
673671
} else {
@@ -676,7 +674,7 @@ range_pattern_helper_data range_pattern_helper_shared(pluginID_t plugin, struct
676674
}
677675

678676
if (isWritePattern) { // write pattern is present
679-
data.write = event->Par3 & ((1 << data.numBytes * 8) - 1); // limit number of bytes
677+
data.write = event->Par3 & ((1 << (data.numBytes * 8)) - 1); // limit number of bytes
680678
data.write &= ((1 << data.numBits) - 1); // limit to number of bits
681679
data.write = data.write << data.deltaStart; // shift to start from starting pin
682680
} else { // write pattern not present

src/src/Commands/InternalCommands.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ command_case_data::command_case_data(const char *cmd, struct EventStruct *event,
133133

134134
// Wrapper to reduce generated code by macro
135135
bool do_command_case_all(command_case_data & data,
136-
const String & cmd_test,
136+
const __FlashStringHelper * cmd_test,
137137
command_function_fs pFunc,
138138
int nrArguments)
139139
{
@@ -142,7 +142,7 @@ bool do_command_case_all(command_case_data & data,
142142

143143

144144
bool do_command_case_all(command_case_data & data,
145-
const String & cmd_test,
145+
const __FlashStringHelper * cmd_test,
146146
command_function pFunc,
147147
int nrArguments)
148148
{
@@ -151,7 +151,7 @@ bool do_command_case_all(command_case_data & data,
151151

152152
// Wrapper to reduce generated code by macro
153153
bool do_command_case_all_restricted(command_case_data & data,
154-
const String & cmd_test,
154+
const __FlashStringHelper * cmd_test,
155155
command_function_fs pFunc,
156156
int nrArguments)
157157
{
@@ -160,7 +160,7 @@ bool do_command_case_all_restricted(command_case_data & data,
160160

161161

162162
bool do_command_case_all_restricted(command_case_data & data,
163-
const String & cmd_test,
163+
const __FlashStringHelper * cmd_test,
164164
command_function pFunc,
165165
int nrArguments)
166166
{
@@ -169,9 +169,9 @@ bool do_command_case_all_restricted(command_case_data & data,
169169

170170

171171
bool do_command_case_check(command_case_data & data,
172-
const String & cmd_test,
173-
int nrArguments,
174-
EventValueSourceGroup::Enum group)
172+
const __FlashStringHelper * cmd_test,
173+
int nrArguments,
174+
EventValueSourceGroup::Enum group)
175175
{
176176
// The data struct is re-used on each attempt to process an internal command.
177177
// Re-initialize the only two members that may have been altered by a previous call.
@@ -202,7 +202,7 @@ bool do_command_case_check(command_case_data & data,
202202
}
203203

204204
bool do_command_case(command_case_data & data,
205-
const String & cmd_test,
205+
const __FlashStringHelper * cmd_test,
206206
command_function_fs pFunc,
207207
int nrArguments,
208208
EventValueSourceGroup::Enum group)
@@ -217,7 +217,7 @@ bool do_command_case(command_case_data & data,
217217

218218

219219
bool do_command_case(command_case_data & data,
220-
const String & cmd_test,
220+
const __FlashStringHelper * cmd_test,
221221
command_function pFunc,
222222
int nrArguments,
223223
EventValueSourceGroup::Enum group)

src/src/Commands/InternalCommands.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ struct command_case_data {
3232

3333
};
3434

35-
bool do_command_case(command_case_data& data, const String& cmd_test, command_function_fs pFunc, int nrArguments, EventValueSourceGroup::Enum group);
36-
bool do_command_case(command_case_data& data, const String& cmd_test, command_function pFunc, int nrArguments, EventValueSourceGroup::Enum group);
35+
bool do_command_case(command_case_data& data, const __FlashStringHelper * cmd_test, command_function_fs pFunc, int nrArguments, EventValueSourceGroup::Enum group);
36+
bool do_command_case(command_case_data& data, const __FlashStringHelper * cmd_test, command_function pFunc, int nrArguments, EventValueSourceGroup::Enum group);
3737

3838

3939
/*********************************************************************************************\

src/src/Commands/MQTT.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ const __FlashStringHelper * Command_MQTT_Subscribe(struct EventStruct *event, co
105105
String eventName = Line;
106106
String topic = eventName.substring(10);
107107
if (!MQTTsubscribe(enabledMqttController, topic.c_str(), mqtt_retainFlag))
108-
return_command_failed();
109-
return_command_success();
108+
return return_command_failed();
109+
return return_command_success();
110110
}
111111
return F("No MQTT controller enabled");
112112
}

src/src/ControllerQueue/C016_queue_element.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ C016_queue_element::C016_queue_element(const struct EventStruct *event, byte val
3737
}
3838
}
3939

40+
C016_queue_element& C016_queue_element::operator=(C016_queue_element&& other) {
41+
_timestamp = other._timestamp;
42+
TaskIndex = other.TaskIndex;
43+
controller_idx = other.controller_idx;
44+
sensorType = other.sensorType;
45+
valueCount = other.valueCount;
46+
for (byte i = 0; i < VARS_PER_TASK; ++i) {
47+
values[i] = other.values[i];
48+
}
49+
return *this;
50+
}
51+
4052
size_t C016_queue_element::getSize() const {
4153
return sizeof(*this);
4254
}

src/src/ControllerQueue/C016_queue_element.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class C016_queue_element {
2929
byte value_count,
3030
unsigned long unixTime);
3131

32+
C016_queue_element& operator=(C016_queue_element&& other);
33+
34+
3235
size_t getSize() const;
3336

3437
bool isDuplicate(const C016_queue_element& other) const;

src/src/ControllerQueue/ControllerDelayHandlerStruct.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ struct ControllerDelayHandlerStruct {
8989
#ifndef BUILD_NO_DEBUG
9090

9191
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
92-
String log = "Controller-";
92+
String log = F("Controller-");
9393
log += element.controller_idx + 1;
94-
log += " : Memory used: ";
94+
log += F(" : Memory used: ");
9595
log += getQueueMemorySize();
96-
log += " bytes ";
96+
log += F(" bytes ");
9797
log += sendQueue.size();
98-
log += " items ";
98+
log += F(" items ");
9999
log += freeHeap;
100-
log += " free";
100+
log += F(" free");
101101
addLog(LOG_LEVEL_DEBUG, log);
102102
}
103103
#endif // ifndef BUILD_NO_DEBUG

0 commit comments

Comments
 (0)