Skip to content

Commit 11f7d17

Browse files
committed
remove (std::nothrow) where nullptr case is not handled
remove legacy new management
1 parent a16e1e5 commit 11f7d17

File tree

42 files changed

+125
-326
lines changed

Some content is hidden

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

42 files changed

+125
-326
lines changed

boards.txt

+34-136
Large diffs are not rendered by default.

cores/esp8266/FunctionalInterrupt.cpp

+9-29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ typedef void (*voidFuncPtr)(void);
77
typedef void (*voidFuncPtrArg)(void*);
88

99
// Helper functions for Functional interrupt routines
10-
extern "C" bool __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtr userFunc, void*fp, int mode, bool functional);
10+
extern "C" void __attachInterruptFunctionalArg(uint8_t pin, voidFuncPtr userFunc, void*fp, int mode, bool functional);
1111

1212

1313
void ICACHE_RAM_ATTR interruptFunctional(void* arg)
@@ -34,52 +34,32 @@ extern "C"
3434
}
3535
}
3636

37-
bool attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode)
37+
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode)
3838
{
3939
// use the local interrupt routine which takes the ArgStructure as argument
4040

4141
InterruptInfo* ii = nullptr;
4242

43-
FunctionInfo* fi = new (std::nothrow) FunctionInfo;
44-
if (fi == nullptr)
45-
return false;
43+
FunctionInfo* fi = new FunctionInfo;
4644
fi->reqFunction = intRoutine;
4745

48-
ArgStructure* as = new (std::nothrow) ArgStructure;
49-
if (as == nullptr)
50-
{
51-
delete(fi);
52-
return false;
53-
}
46+
ArgStructure* as = new ArgStructure;
5447
as->interruptInfo = ii;
5548
as->functionInfo = fi;
5649

57-
return __attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
50+
__attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
5851
}
5952

60-
bool attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode)
53+
void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode)
6154
{
62-
InterruptInfo* ii = new (std::nothrow) InterruptInfo;
63-
if (ii == nullptr)
64-
return false;
55+
InterruptInfo* ii = new InterruptInfo;
6556

6657
FunctionInfo* fi = new FunctionInfo;
67-
if (fi == nullptr)
68-
{
69-
delete ii;
70-
return false;
71-
}
7258
fi->reqScheduledFunction = scheduledIntRoutine;
7359

74-
ArgStructure* as = new (std::nothrow) ArgStructure;
75-
if (as == nullptr)
76-
{
77-
delete ii;
78-
delete fi;
79-
return false;
80-
}
60+
ArgStructure* as = new ArgStructure;
8161
as->interruptInfo = ii;
8262
as->functionInfo = fi;
8363

84-
return __attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
64+
__attachInterruptFunctionalArg(pin, (voidFuncPtr)interruptFunctional, as, mode, true);
8565
}

cores/esp8266/FunctionalInterrupt.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ struct ArgStructure {
2828
FunctionInfo* functionInfo = nullptr;
2929
};
3030

31-
bool attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
32-
bool attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode);
31+
void attachInterrupt(uint8_t pin, std::function<void(void)> intRoutine, int mode);
32+
void attachScheduledInterrupt(uint8_t pin, std::function<void(InterruptInfo)> scheduledIntRoutine, int mode);
3333

3434

3535
#endif //INTERRUPTS_H

cores/esp8266/Updater.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
182182
} else {
183183
_bufferSize = 256;
184184
}
185-
_buffer = new (std::nothrow) uint8_t[_bufferSize];
185+
_buffer = new uint8_t[_bufferSize];
186186
_command = command;
187187

188188
#ifdef DEBUG_UPDATER

libraries/ArduinoOTA/ArduinoOTA.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ void ArduinoOTAClass::setRebootOnSuccess(bool reboot){
106106
_rebootOnSuccess = reboot;
107107
}
108108

109-
bool ArduinoOTAClass::begin(bool useMDNS) {
109+
void ArduinoOTAClass::begin(bool useMDNS) {
110110
if (_initialized)
111-
return true;
111+
return;
112112

113113
_useMDNS = useMDNS;
114114

@@ -126,13 +126,11 @@ bool ArduinoOTAClass::begin(bool useMDNS) {
126126
_udp_ota = 0;
127127
}
128128

129-
_udp_ota = new (std::nothrow) UdpContext;
130-
if (_udp_ota == nullptr)
131-
return false;
129+
_udp_ota = new UdpContext;
132130
_udp_ota->ref();
133131

134132
if(!_udp_ota->listen(IP_ADDR_ANY, _port))
135-
return false;
133+
return;
136134
_udp_ota->onRx(std::bind(&ArduinoOTAClass::_onRx, this));
137135

138136
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_MDNS)
@@ -151,7 +149,6 @@ bool ArduinoOTAClass::begin(bool useMDNS) {
151149
#ifdef OTA_DEBUG
152150
OTA_DEBUG.printf("OTA server at: %s.local:%u\n", _hostname.c_str(), _port);
153151
#endif
154-
return true;
155152
}
156153

157154
int ArduinoOTAClass::parseInt(){

libraries/ArduinoOTA/ArduinoOTA.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ArduinoOTAClass
6060
void onProgress(THandlerFunction_Progress fn);
6161

6262
//Starts the ArduinoOTA service
63-
bool begin(bool useMDNS = true);
63+
void begin(bool useMDNS = true);
6464

6565
//Call this in loop() to run the service. Also calls MDNS.update() when begin() or begin(true) is used.
6666
void handle();

libraries/EEPROM/EEPROM.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ void EEPROMClass::begin(size_t size) {
6464
//In case begin() is called a 2nd+ time, don't reallocate if size is the same
6565
if(_data && size != _size) {
6666
delete[] _data;
67-
_data = new (std::nothrow) uint8_t[size];
67+
_data = new uint8_t[size];
6868
} else if(!_data) {
69-
_data = new (std::nothrow) uint8_t[size];
70-
}
71-
if (_data == nullptr) {
72-
return;
69+
_data = new uint8_t[size];
7370
}
7471

7572
_size = size;

libraries/ESP8266HTTPClient/examples/BasicHttpsClient/BasicHttpsClient.ino

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ void loop() {
4141
// wait for WiFi connection
4242
if ((WiFiMulti.run() == WL_CONNECTED)) {
4343

44-
std::unique_ptr<BearSSL::WiFiClientSecure>client(new (std::nothrow) BearSSL::WiFiClientSecure);
45-
if (client == nullptr) {
46-
return;
47-
}
44+
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
4845

4946
client->setFingerprint(fingerprint);
5047

libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino

+1-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ void loop() {
3838
// wait for WiFi connection
3939
if ((WiFiMulti.run() == WL_CONNECTED)) {
4040

41-
std::unique_ptr<BearSSL::WiFiClientSecure> client(new (std::nothrow) BearSSL::WiFiClientSecure);
42-
if (client == nullptr) {
43-
return;
44-
}
41+
std::unique_ptr<BearSSL::WiFiClientSecure> client(new BearSSL::WiFiClientSecure);
4542

4643
bool mfln = client->probeMaxFragmentLength("tls.mbed.org", 443, 1024);
4744
Serial.printf("\nConnecting to https://tls.mbed.org\n");

libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TransportTraits
3737

3838
virtual std::unique_ptr<WiFiClient> create()
3939
{
40-
return std::unique_ptr<WiFiClient>(new (std::nothrow) WiFiClient());
40+
return std::unique_ptr<WiFiClient>(new WiFiClient());
4141
}
4242

4343
virtual bool verify(WiFiClient& client, const char* host)
@@ -59,9 +59,8 @@ class BearSSLTraits : public TransportTraits
5959

6060
std::unique_ptr<WiFiClient> create() override
6161
{
62-
BearSSL::WiFiClientSecure *client = new (std::nothrow) BearSSL::WiFiClientSecure();
63-
if (client != nullptr)
64-
client->setFingerprint(_fingerprint);
62+
BearSSL::WiFiClientSecure *client = new BearSSL::WiFiClientSecure();
63+
client->setFingerprint(_fingerprint);
6564
return std::unique_ptr<WiFiClient>(client);
6665
}
6766

@@ -213,8 +212,8 @@ bool HTTPClient::begin(String url)
213212
if (!beginInternal(url, "http")) {
214213
return false;
215214
}
216-
_transportTraits = TransportTraitsPtr(new (std::nothrow) TransportTraits());
217-
return _transportTraits != nullptr;
215+
_transportTraits = TransportTraitsPtr(new TransportTraits());
216+
return true;
218217
}
219218

220219

@@ -291,9 +290,9 @@ bool HTTPClient::begin(String host, uint16_t port, String uri)
291290
_host = host;
292291
_port = port;
293292
_uri = uri;
294-
_transportTraits = TransportTraitsPtr(new (std::nothrow) TransportTraits());
293+
_transportTraits = TransportTraitsPtr(new TransportTraits());
295294
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d uri: %s\n", host.c_str(), port, uri.c_str());
296-
return _transportTraits != nullptr;
295+
return true;
297296
}
298297

299298

@@ -310,13 +309,13 @@ bool HTTPClient::begin(String host, uint16_t port, String uri, const uint8_t htt
310309
_port = port;
311310
_uri = uri;
312311

313-
_transportTraits = TransportTraitsPtr(new (std::nothrow) BearSSLTraits(httpsFingerprint));
312+
_transportTraits = TransportTraitsPtr(new BearSSLTraits(httpsFingerprint));
314313
DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s BearSSL-httpsFingerprint:", host.c_str(), port, uri.c_str());
315314
for (size_t i=0; i < 20; i++) {
316315
DEBUG_HTTPCLIENT(" %02x", httpsFingerprint[i]);
317316
}
318317
DEBUG_HTTPCLIENT("\n");
319-
return _transportTraits != nullptr;
318+
return true;
320319
}
321320

322321

libraries/ESP8266HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void setup()
106106

107107
MDNS.begin(host);
108108

109-
httpServer.getServer().setRSACert(new (std::nothrow) BearSSL::X509List(serverCert), new (std::nothrow) BearSSL::PrivateKey(serverKey));
109+
httpServer.getServer().setRSACert(new BearSSL::X509List(serverCert), new BearSSL::PrivateKey(serverKey));
110110
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
111111
httpServer.begin();
112112

libraries/ESP8266LLMNR/ESP8266LLMNR.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ bool LLMNRResponder::_restart() {
116116
if (igmp_joingroup(IP4_ADDR_ANY4, llmnr) != ERR_OK)
117117
return false;
118118

119-
_conn = new (std::nothrow) UdpContext;
120-
if (!_conn)
121-
return false;
119+
_conn = new UdpContext;
122120
_conn->ref();
123121

124122
if (!_conn->listen(IP_ADDR_ANY, LLMNR_PORT))

libraries/ESP8266SSDP/ESP8266SSDP.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ bool SSDPClass::begin() {
175175

176176
assert(NULL == _server);
177177

178-
_server = new (std::nothrow) UdpContext;
179-
if (_server == nullptr) {
180-
return false;
181-
}
178+
_server = new UdpContext;
182179
_server->ref();
183180

184181
IPAddress local = WiFi.localIP();
@@ -511,9 +508,7 @@ void SSDPClass::_onTimerStatic(SSDPClass* self) {
511508

512509
void SSDPClass::_startTimer() {
513510
_stopTimer();
514-
_timer = new (std::nothrow) SSDPTimer();
515-
if (_timer == nullptr)
516-
return;
511+
_timer = new SSDPTimer();
517512
ETSTimer* tm = &(_timer->timer);
518513
const int interval = 1000;
519514
os_timer_disarm(tm);

libraries/ESP8266WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void setup(void){
128128
Serial.println("MDNS responder started");
129129
}
130130

131-
server.getServer().setRSACert(new (std::nothrow) BearSSL::X509List(serverCert), new (std::nothrow) BearSSL::PrivateKey(serverKey));
131+
server.getServer().setRSACert(new BearSSL::X509List(serverCert), new BearSSL::PrivateKey(serverKey));
132132

133133
server.on("/", handleRoot);
134134

libraries/ESP8266WebServer/examples/HttpHashCredAuth/HttpHashCredAuth.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void setup() {
111111
ESP.restart();
112112
}
113113

114-
server.getServer().setRSACert(new (std::nothrow) BearSSL::X509List(serverCert), new (std::nothrow) BearSSL::PrivateKey(serverKey));
114+
server.getServer().setRSACert(new BearSSL::X509List(serverCert), new BearSSL::PrivateKey(serverKey));
115115
server.on("/",showcredentialpage); //for this simple example, just show a simple page for changing credentials at the root
116116
server.on("/" + change_creds,handlecredentialchange); //handles submission of credentials from the client
117117
server.onNotFound(redirect);

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void ESP8266WebServerTemplate<ServerType>::on(const Uri &uri, HTTPMethod method,
266266

267267
template <typename ServerType>
268268
void ESP8266WebServerTemplate<ServerType>::on(const Uri &uri, HTTPMethod method, ESP8266WebServerTemplate<ServerType>::THandlerFunction fn, ESP8266WebServerTemplate<ServerType>::THandlerFunction ufn) {
269-
_addRequestHandler(new (std::nothrow) FunctionRequestHandler<ServerType>(fn, ufn, uri, method));
269+
_addRequestHandler(new FunctionRequestHandler<ServerType>(fn, ufn, uri, method));
270270
}
271271

272272
template <typename ServerType>
@@ -288,7 +288,7 @@ void ESP8266WebServerTemplate<ServerType>::_addRequestHandler(RequestHandlerType
288288

289289
template <typename ServerType>
290290
void ESP8266WebServerTemplate<ServerType>::serveStatic(const char* uri, FS& fs, const char* path, const char* cache_header) {
291-
_addRequestHandler(new (std::nothrow) StaticRequestHandler<ServerType>(fs, path, uri, cache_header));
291+
_addRequestHandler(new StaticRequestHandler<ServerType>(fs, path, uri, cache_header));
292292
}
293293

294294
template <typename ServerType>
@@ -645,9 +645,7 @@ void ESP8266WebServerTemplate<ServerType>::collectHeaders(const char* headerKeys
645645
_headerKeysCount = headerKeysCount + 1;
646646
if (_currentHeaders)
647647
delete[]_currentHeaders;
648-
_currentHeaders = new (std::nothrow) RequestArgument[_headerKeysCount];
649-
if (_currentHeaders == nullptr)
650-
return;
648+
_currentHeaders = new RequestArgument[_headerKeysCount];
651649
_currentHeaders[0].key = FPSTR(AUTHORIZATION_HEADER);
652650
for (int i = 1; i < _headerKeysCount; i++){
653651
_currentHeaders[i].key = headerKeys[i-1];

libraries/ESP8266WebServer/src/Parsing-impl.h

+4-16
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ void ESP8266WebServerTemplate<ServerType>::_parseArguments(const String& data) {
283283
_currentArgCount = _parseArgumentsPrivate(data, nullArgHandler());
284284

285285
// allocate one more, this is needed because {"plain": plainBuf} is always added
286-
_currentArgs = new (std::nothrow) RequestArgument[_currentArgCount + 1];
287-
if (_currentArgs == nullptr)
288-
return;
286+
_currentArgs = new RequestArgument[_currentArgCount + 1];
289287

290288
(void)_parseArgumentsPrivate(data, storeArgHandler<ServerType>());
291289
}
@@ -372,11 +370,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
372370
//start reading the form
373371
if (line == ("--"+boundary)){
374372
if(_postArgs) delete[] _postArgs;
375-
_postArgs = new (std::nothrow) RequestArgument[WEBSERVER_MAX_POST_ARGS];
376-
if (_postArgs == nullptr) {
377-
DBGWS("Parse form: oom\n");
378-
return false;
379-
}
373+
_postArgs = new RequestArgument[WEBSERVER_MAX_POST_ARGS];
380374
_postArgsLen = 0;
381375
while(1){
382376
String argName;
@@ -434,11 +428,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
434428
break;
435429
}
436430
} else {
437-
_currentUpload.reset(new (std::nothrow) HTTPUpload());
438-
if (_currentUpload == nullptr) {
439-
DBGWS("Parse form: oom\n");
440-
return false;
441-
}
431+
_currentUpload.reset(new HTTPUpload());
442432
_currentUpload->status = UPLOAD_FILE_START;
443433
_currentUpload->name = argName;
444434
_currentUpload->filename = argFilename;
@@ -531,9 +521,7 @@ bool ESP8266WebServerTemplate<ServerType>::_parseForm(ClientType& client, const
531521
arg.value = _currentArgs[iarg].value;
532522
}
533523
if (_currentArgs) delete[] _currentArgs;
534-
_currentArgs = new (std::nothrow) RequestArgument[_postArgsLen];
535-
if (_currentArgs == nullptr)
536-
return false;
524+
_currentArgs = new RequestArgument[_postArgsLen];
537525
for (iarg = 0; iarg < _postArgsLen; iarg++){
538526
RequestArgument& arg = _currentArgs[iarg];
539527
arg.key = _postArgs[iarg].key;

libraries/ESP8266WebServer/src/Uri.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Uri {
1616
virtual ~Uri() {}
1717

1818
virtual Uri* clone() const {
19-
return new (std::nothrow) Uri(_uri);
19+
return new Uri(_uri);
2020
};
2121

2222
virtual bool canHandle(const String &requestUri, __attribute__((unused)) std::vector<String> &pathArgs) {

libraries/ESP8266WebServer/src/uri/UriBraces.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class UriBraces : public Uri {
1010
explicit UriBraces(const String &uri) : Uri(uri) {};
1111

1212
Uri* clone() const override final {
13-
return new (std::nothrow) UriBraces(_uri);
13+
return new UriBraces(_uri);
1414
};
1515

1616
bool canHandle(const String &requestUri, std::vector<String> &pathArgs) override final {

libraries/ESP8266WebServer/src/uri/UriGlob.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class UriGlob : public Uri {
1111
explicit UriGlob(const String &uri) : Uri(uri) {};
1212

1313
Uri* clone() const override final {
14-
return new (std::nothrow) UriGlob(_uri);
14+
return new UriGlob(_uri);
1515
};
1616

1717
bool canHandle(const String &requestUri, __attribute__((unused)) std::vector<String> &pathArgs) override final {

0 commit comments

Comments
 (0)