1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-07 06:01:35 +03:00

remove (std::nothrow) where nullptr case is not handled

remove legacy new management
This commit is contained in:
david gauchard
2020-08-24 09:51:58 +02:00
parent a16e1e5b8a
commit 11f7d1766e
42 changed files with 125 additions and 326 deletions

View File

@ -109,7 +109,7 @@ namespace brssl {
}
static bool certificate_to_trust_anchor_inner(br_x509_trust_anchor *ta, const br_x509_certificate *xc) {
std::unique_ptr<br_x509_decoder_context> dc(new (std::nothrow) br_x509_decoder_context); // auto-delete on exit
std::unique_ptr<br_x509_decoder_context> dc(new br_x509_decoder_context); // auto-delete on exit
std::vector<uint8_t> vdn;
br_x509_pkey *pk;
@ -244,7 +244,7 @@ namespace brssl {
// blobs may be returned.
pem_object *decode_pem(const void *src, size_t len, size_t *num) {
std::vector<pem_object> pem_list;
std::unique_ptr<br_pem_decoder_context> pc(new (std::nothrow) br_pem_decoder_context); // auto-delete on exit
std::unique_ptr<br_pem_decoder_context> pc(new br_pem_decoder_context); // auto-delete on exit
if (!pc.get()) {
return nullptr;
}
@ -405,7 +405,7 @@ namespace brssl {
}
static public_key *decode_public_key(const unsigned char *buff, size_t len) {
std::unique_ptr<br_pkey_decoder_context> dc(new (std::nothrow) br_pkey_decoder_context); // auto-delete on exit
std::unique_ptr<br_pkey_decoder_context> dc(new br_pkey_decoder_context); // auto-delete on exit
if (!dc.get()) {
return nullptr;
}
@ -477,7 +477,7 @@ namespace brssl {
}
static private_key *decode_private_key(const unsigned char *buff, size_t len) {
std::unique_ptr<br_skey_decoder_context> dc(new (std::nothrow) br_skey_decoder_context); // auto-delete on exit
std::unique_ptr<br_skey_decoder_context> dc(new br_skey_decoder_context); // auto-delete on exit
if (!dc.get()) {
return nullptr;
}

View File

@ -308,10 +308,7 @@ void ESP8266WiFiScanClass::_scanDone(void* result, int status) {
if(i == 0) {
ESP8266WiFiScanClass::_scanResult = 0;
} else {
bss_info* copied_info = new (std::nothrow) bss_info[i];
if (copied_info == nullptr) {
return;
}
bss_info* copied_info = new bss_info[i];
i = 0;
for(bss_info* it = head; it; it = STAILQ_NEXT(it, next), ++i) {
memcpy(copied_info + i, it, sizeof(bss_info));

View File

@ -153,10 +153,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port)
pcb->local_port = _localPort++;
}
_client = new (std::nothrow) ClientContext(pcb, nullptr, nullptr);
if (_client == nullptr) {
return 0;
}
_client = new ClientContext(pcb, nullptr, nullptr);
_client->ref();
_client->setTimeout(_timeout);
int res = _client->connect(ip, port);

View File

@ -1580,21 +1580,21 @@ bool WiFiClientSecure::probeMaxFragmentLength(IPAddress ip, uint16_t port, uint1
// AXTLS compatibility interfaces
bool WiFiClientSecure::setCACert(const uint8_t* pk, size_t size) {
_axtls_ta = nullptr;
_axtls_ta = std::shared_ptr<X509List>(new (std::nothrow) X509List(pk, size));
_axtls_ta = std::shared_ptr<X509List>(new X509List(pk, size));
_ta = _axtls_ta.get();
return _ta ? true : false;
}
bool WiFiClientSecure::setCertificate(const uint8_t* pk, size_t size) {
_axtls_chain = nullptr;
_axtls_chain = std::shared_ptr<X509List>(new (std::nothrow) X509List(pk, size));
_axtls_chain = std::shared_ptr<X509List>(new X509List(pk, size));
_chain = _axtls_chain.get();
return _chain ? true : false;
}
bool WiFiClientSecure::setPrivateKey(const uint8_t* pk, size_t size) {
_axtls_sk = nullptr;
_axtls_sk = std::shared_ptr<PrivateKey>(new (std::nothrow) PrivateKey(pk, size));
_axtls_sk = std::shared_ptr<PrivateKey>(new PrivateKey(pk, size));
_sk = _axtls_sk.get();
return _sk ? true : false;

View File

@ -186,10 +186,7 @@ long WiFiServer::_accept(tcp_pcb* apcb, long err) {
// always accept new PCB so incoming data can be stored in our buffers even before
// user calls ::available()
ClientContext* client = new (std::nothrow) ClientContext(apcb, &WiFiServer::_s_discard, this);
if (client == nullptr) {
return ERR_MEM;
}
ClientContext* client = new ClientContext(apcb, &WiFiServer::_s_discard, this);
// backlog doc:
// http://lwip.100.n7.nabble.com/Problem-re-opening-listening-pbc-tt32484.html#a32494

View File

@ -107,8 +107,8 @@ WiFiClientSecure WiFiServerSecure::available(uint8_t* status) {
void WiFiServerSecure::setServerKeyAndCert(const uint8_t *key, int keyLen, const uint8_t *cert, int certLen) {
_axtls_chain = nullptr;
_axtls_sk = nullptr;
_axtls_chain = std::shared_ptr<X509List>(new (std::nothrow) X509List(cert, certLen));
_axtls_sk = std::shared_ptr<PrivateKey>(new (std::nothrow) PrivateKey(key, keyLen));
_axtls_chain = std::shared_ptr<X509List>(new X509List(cert, certLen));
_axtls_sk = std::shared_ptr<PrivateKey>(new PrivateKey(key, keyLen));
setRSACert(_axtls_chain.get(), _axtls_sk.get());
}

View File

@ -80,10 +80,7 @@ uint8_t WiFiUDP::begin(uint16_t port)
_ctx = 0;
}
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx = new UdpContext;
_ctx->ref();
return (_ctx->listen(IPAddress(), port)) ? 1 : 0;
}
@ -99,10 +96,7 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
return 0;
}
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx = new UdpContext;
_ctx->ref();
ip_addr_t addr = IPADDR4_INIT(INADDR_ANY);
if (!_ctx->listen(&addr, port)) {
@ -153,10 +147,7 @@ int WiFiUDP::beginPacket(const char *host, uint16_t port)
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
{
if (!_ctx) {
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx = new UdpContext;
_ctx->ref();
}
return (_ctx->connect(ip, port)) ? 1 : 0;
@ -166,10 +157,7 @@ int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
IPAddress interfaceAddress, int ttl)
{
if (!_ctx) {
_ctx = new (std::nothrow) UdpContext;
if (_ctx == nullptr) {
return 0;
}
_ctx = new UdpContext;
_ctx->ref();
}
if (!_ctx->connect(multicastAddress, port)) {

View File

@ -374,7 +374,7 @@ public:
if (!_pcb) {
return 0;
}
return _write_from_source(new (std::nothrow) BufferDataSource(data, size));
return _write_from_source(new BufferDataSource(data, size));
}
size_t write(Stream& stream)
@ -382,7 +382,7 @@ public:
if (!_pcb) {
return 0;
}
return _write_from_source(new (std::nothrow) BufferedStreamDataSource<Stream>(stream, stream.available()));
return _write_from_source(new BufferedStreamDataSource<Stream>(stream, stream.available()));
}
size_t write_P(PGM_P buf, size_t size)
@ -391,7 +391,7 @@ public:
return 0;
}
ProgmemStream stream(buf, size);
return _write_from_source(new (std::nothrow) BufferedStreamDataSource<ProgmemStream>(stream, size));
return _write_from_source(new BufferedStreamDataSource<ProgmemStream>(stream, size));
}
void keepAlive (uint16_t idle_sec = TCP_DEFAULT_KEEPALIVE_IDLE_SEC, uint16_t intv_sec = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC, uint8_t count = TCP_DEFAULT_KEEPALIVE_COUNT)

View File

@ -75,7 +75,7 @@ public:
//Buffer too small?
if (_bufferSize < min_buffer_size) {
uint8_t *new_buffer = new (std::nothrow) uint8_t[min_buffer_size];
uint8_t *new_buffer = new uint8_t[min_buffer_size];
//If stream reading is ahead, than some data is already in the old buffer and needs to be copied to new resized buffer
if (_buffer && stream_read > 0) {
memcpy(new_buffer, _buffer.get(), stream_read);