Skip to content

Commit 6f1dcae

Browse files
committed
[new new] Prepare for upcoming changes of 'new' in esp8266/Arduino
See esp8266/Arduino#7536
1 parent 6622ac8 commit 6f1dcae

Some content is hidden

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

45 files changed

+115
-80
lines changed

lib/SerialDevices/jkSDS011.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ CjkSDS011::CjkSDS011(int16_t pinRX, int16_t pinTX)
3838
_command.SetPacketLength(19);
3939
_working_period = -1;
4040
_sleepmode_active = false;
41-
_serial = new ESPeasySerial(pinRX, pinTX);
42-
_serial->begin(9600);
41+
_serial = new (std::nothrow) ESPeasySerial(pinRX, pinTX);
42+
if (_serial != nullptr)
43+
_serial->begin(9600);
4344
}
4445

4546
CjkSDS011::~CjkSDS011() {

lib/SerialDevices/jkSDS011.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CjkSDS011
6464
void ParseCommandReply();
6565

6666
// SensorSerial _serial;
67-
ESPeasySerial *_serial;
67+
ESPeasySerial *_serial = nullptr;
6868
CSensorSerialBuffer _data;
6969
CSensorSerialBuffer _command;
7070
float _pm2_5;

src/ESPeasyControllerCache.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct ControllerCache_struct {
3333

3434
void init() {
3535
if (_RTC_cache_handler == nullptr) {
36-
_RTC_cache_handler = new RTC_cache_handler_struct;
36+
_RTC_cache_handler = new (std::nothrow) RTC_cache_handler_struct;
3737
}
3838
}
3939

src/Networking.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ bool SSDP_begin() {
568568

569569
if (_server) {
570570
_server->unref();
571+
571572
_server = 0;
572573
}
573574

@@ -650,7 +651,8 @@ void SSDP_send(byte method) {
650651
(uint16_t)((chipId >> 8) & 0xff),
651652
(uint16_t)chipId & 0xff);
652653

653-
char *buffer = new char[1460]();
654+
char *buffer = new (std::nothrow) char[1460]();
655+
if (buffer == nullptr) { return; }
654656
int len = snprintf(buffer, 1460,
655657
_ssdp_packet_template.c_str(),
656658
(method == 0) ? _ssdp_response_template.c_str() : _ssdp_notify_template.c_str(),

src/_C018.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct C018_data_struct {
7474
_baudrate = baudrate;
7575

7676
// FIXME TD-er: Make force SW serial a proper setting.
77-
C018_easySerial = new ESPeasySerial(serial_rx, serial_tx, false, 64, C018_FORCE_SW_SERIAL);
77+
C018_easySerial = new (std::nothrow) ESPeasySerial(serial_rx, serial_tx, false, 64, C018_FORCE_SW_SERIAL);
7878

7979
if (C018_easySerial != nullptr) {
8080
myLora = new rn2xx3(*C018_easySerial);

src/_P002_ADC.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ boolean Plugin_002(byte function, struct EventStruct *event, String& string)
191191

192192
case PLUGIN_INIT:
193193
{
194-
initPluginTaskData(event->TaskIndex, new P002_data_struct());
194+
initPluginTaskData(event->TaskIndex, new (std::nothrow) P002_data_struct());
195195
P002_data_struct *P002_data =
196196
static_cast<P002_data_struct *>(getPluginTaskData(event->TaskIndex));
197197

src/_P014_SI7021.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ boolean Plugin_014(byte function, struct EventStruct *event, String& string)
445445
{
446446
// Get sensor resolution configuration
447447
uint8_t res = PCONFIG(0);
448-
initPluginTaskData(event->TaskIndex, new P014_data_struct(res));
448+
initPluginTaskData(event->TaskIndex, new (std::nothrow) P014_data_struct(res));
449449
P014_data_struct *P014_data =
450450
static_cast<P014_data_struct *>(getPluginTaskData(event->TaskIndex));
451451

src/_P031_SHT1X.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ boolean Plugin_031(byte function, struct EventStruct *event, String& string)
314314

315315
case PLUGIN_INIT:
316316
{
317-
initPluginTaskData(event->TaskIndex, new P031_data_struct());
317+
initPluginTaskData(event->TaskIndex, new (std::nothrow) P031_data_struct());
318318
P031_data_struct *P031_data =
319319
static_cast<P031_data_struct *>(getPluginTaskData(event->TaskIndex));
320320
if (nullptr == P031_data) {

src/_P035_IRTX.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ boolean Plugin_035(byte function, struct EventStruct *event, String &command)
116116
}
117117

118118
#ifdef P016_P035_Extended_AC
119-
if (Plugin_035_commonAc == 0 && irPin != -1)
119+
if (Plugin_035_commonAc == nullptr && irPin != -1)
120120
{
121121
addLog(LOG_LEVEL_INFO, F("INIT AC: IR TX"));
122122
addLog(LOG_LEVEL_INFO, String(F("Supported Protocols by IRSENDAC: ")) + listACProtocols());
123-
Plugin_035_commonAc = new IRac(irPin);
123+
Plugin_035_commonAc = new (std::nothrow) IRac(irPin);
124124
}
125-
if (Plugin_035_commonAc != 0 && irPin == -1)
125+
if (Plugin_035_commonAc != nullptr && irPin == -1)
126126
{
127127
addLog(LOG_LEVEL_INFO, F("INIT AC: IR TX Removed"));
128128
delete Plugin_035_commonAc;
@@ -298,7 +298,7 @@ boolean handleRawRaw2Encoding(const String &cmd) {
298298

299299
uint16_t idx = 0; //If this goes above the buf.size then the esp will throw a 28 EXCCAUSE
300300
uint16_t *buf;
301-
buf = new uint16_t[P35_Ntimings]; //The Raw Timings that we can buffer.
301+
buf = new (std::nothrow) uint16_t[P35_Ntimings]; //The Raw Timings that we can buffer.
302302
if (buf == nullptr)
303303
{ // error assigning memory.
304304
return false;

src/_P036_FrameOLED.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
243243
// For load and save of the display lines, we must not rely on the data in memory.
244244
// This data in memory can be altered through write commands.
245245
// Therefore we must read the lines from flash in a temporary object.
246-
P036_data_struct *P036_data = new P036_data_struct();
246+
P036_data_struct *P036_data = new (std::nothrow) P036_data_struct();
247247

248248
if (nullptr != P036_data) {
249249
uint8_t version = get4BitFromUL(PCONFIG_LONG(0), 20); // Bit23-20 Version CustomTaskSettings
@@ -302,7 +302,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
302302
// For load and save of the display lines, we must not rely on the data in memory.
303303
// This data in memory can be altered through write commands.
304304
// Therefore we must use a temporary version to store the settings.
305-
P036_data_struct *P036_data = new P036_data_struct();
305+
P036_data_struct *P036_data = new (std::nothrow) P036_data_struct();
306306

307307
if (nullptr != P036_data) {
308308
String error;
@@ -349,7 +349,7 @@ boolean Plugin_036(uint8_t function, struct EventStruct *event, String& string)
349349

350350
case PLUGIN_INIT:
351351
{
352-
initPluginTaskData(event->TaskIndex, new P036_data_struct());
352+
initPluginTaskData(event->TaskIndex, new (std::nothrow) P036_data_struct());
353353
P036_data_struct *P036_data =
354354
static_cast<P036_data_struct *>(getPluginTaskData(event->TaskIndex));
355355

0 commit comments

Comments
 (0)