Skip to content

Commit 46a503c

Browse files
Resolve potential crashes
1 parent 0d84018 commit 46a503c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

libraries/WebServer/src/WebServer.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <Arduino.h>
2525
#include <esp32-hal-log.h>
2626
#include <libb64/cencode.h>
27+
#include <new>
2728
#include "WiFiServer.h"
2829
#include "WiFiClient.h"
2930
#include "WebServer.h"
@@ -145,12 +146,12 @@ bool WebServer::authenticate(const char * username, const char * password){
145146
authReq = authReq.substring(6);
146147
authReq.trim();
147148
char toencodeLen = strlen(username)+strlen(password)+1;
148-
char *toencode = new char[toencodeLen + 1];
149+
char *toencode = new(std::nothrow) char[toencodeLen + 1];
149150
if(toencode == NULL){
150151
authReq = "";
151152
return false;
152153
}
153-
char *encoded = new char[base64_encode_expected_len(toencodeLen)+1];
154+
char *encoded = new(std::nothrow) char[base64_encode_expected_len(toencodeLen)+1];
154155
if(encoded == NULL){
155156
authReq = "";
156157
delete[] toencode;

libraries/WiFi/src/WiFiUdp.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uint8_t WiFiUDP::begin(IPAddress address, uint16_t port){
4444

4545
server_port = port;
4646

47-
tx_buffer = new char[1460];
47+
tx_buffer = new(std::nothrow) char[1460];
4848
if(!tx_buffer){
4949
log_e("could not create tx buffer: %d", errno);
5050
return 0;
@@ -136,7 +136,7 @@ int WiFiUDP::beginPacket(){
136136

137137
// allocate tx_buffer if is necessary
138138
if(!tx_buffer){
139-
tx_buffer = new char[1460];
139+
tx_buffer = new(std::nothrow) char[1460];
140140
if(!tx_buffer){
141141
log_e("could not create tx buffer: %d", errno);
142142
return 0;

0 commit comments

Comments
 (0)