From 4d5aa1b8e3f3df3cf9513b329efac3954403e854 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 May 2024 11:24:13 +1000 Subject: [PATCH] AP_Networking: use NEW_NOTHROW for new(std::nothrow) --- libraries/AP_Networking/AP_Networking.cpp | 10 +++++----- libraries/AP_Networking/AP_Networking_ChibiOS.cpp | 2 +- libraries/AP_Networking/AP_Networking_PPP.cpp | 2 +- libraries/AP_Networking/AP_Networking_port.cpp | 14 +++++++------- libraries/AP_Networking/AP_Networking_tests.cpp | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/AP_Networking/AP_Networking.cpp b/libraries/AP_Networking/AP_Networking.cpp index 19016f3f70..63bdb7235a 100644 --- a/libraries/AP_Networking/AP_Networking.cpp +++ b/libraries/AP_Networking/AP_Networking.cpp @@ -148,26 +148,26 @@ void AP_Networking::init() /* when we are a PPP/Ethernet gateway we bring up the ethernet first */ - backend = new AP_Networking_ChibiOS(*this); - backend_PPP = new AP_Networking_PPP(*this); + backend = NEW_NOTHROW AP_Networking_ChibiOS(*this); + backend_PPP = NEW_NOTHROW AP_Networking_PPP(*this); } #endif #if AP_NETWORKING_BACKEND_PPP if (backend == nullptr && AP::serialmanager().have_serial(AP_SerialManager::SerialProtocol_PPP, 0)) { - backend = new AP_Networking_PPP(*this); + backend = NEW_NOTHROW AP_Networking_PPP(*this); } #endif #if AP_NETWORKING_BACKEND_CHIBIOS if (backend == nullptr) { - backend = new AP_Networking_ChibiOS(*this); + backend = NEW_NOTHROW AP_Networking_ChibiOS(*this); } #endif #if AP_NETWORKING_BACKEND_SITL if (backend == nullptr) { - backend = new AP_Networking_SITL(*this); + backend = NEW_NOTHROW AP_Networking_SITL(*this); } #endif diff --git a/libraries/AP_Networking/AP_Networking_ChibiOS.cpp b/libraries/AP_Networking/AP_Networking_ChibiOS.cpp index 889a8526be..4248119a2d 100644 --- a/libraries/AP_Networking/AP_Networking_ChibiOS.cpp +++ b/libraries/AP_Networking/AP_Networking_ChibiOS.cpp @@ -127,7 +127,7 @@ bool AP_Networking_ChibiOS::init() } #endif - thisif = new netif; + thisif = NEW_NOTHROW netif; if (thisif == nullptr) { return false; } diff --git a/libraries/AP_Networking/AP_Networking_PPP.cpp b/libraries/AP_Networking/AP_Networking_PPP.cpp index 18f16f0bdb..6bcf3651bb 100644 --- a/libraries/AP_Networking/AP_Networking_PPP.cpp +++ b/libraries/AP_Networking/AP_Networking_PPP.cpp @@ -96,7 +96,7 @@ bool AP_Networking_PPP::init() return false; } - pppif = new netif; + pppif = NEW_NOTHROW netif; if (pppif == nullptr) { return false; } diff --git a/libraries/AP_Networking/AP_Networking_port.cpp b/libraries/AP_Networking/AP_Networking_port.cpp index 07c35ab070..c5b8a435cc 100644 --- a/libraries/AP_Networking/AP_Networking_port.cpp +++ b/libraries/AP_Networking/AP_Networking_port.cpp @@ -115,7 +115,7 @@ void AP_Networking::Port::thread_create(AP_HAL::MemberProc proc) */ void AP_Networking::Port::udp_client_init(void) { - sock = new SocketAPM(true); + sock = NEW_NOTHROW SocketAPM(true); if (sock == nullptr) { return; } @@ -133,7 +133,7 @@ void AP_Networking::Port::udp_client_init(void) */ void AP_Networking::Port::udp_server_init(void) { - sock = new SocketAPM(true); + sock = NEW_NOTHROW SocketAPM(true); if (sock == nullptr) { return; } @@ -151,7 +151,7 @@ void AP_Networking::Port::udp_server_init(void) */ void AP_Networking::Port::tcp_server_init(void) { - listen_sock = new SocketAPM(false); + listen_sock = NEW_NOTHROW SocketAPM(false); if (listen_sock == nullptr) { return; } @@ -165,7 +165,7 @@ void AP_Networking::Port::tcp_server_init(void) */ void AP_Networking::Port::tcp_client_init(void) { - sock = new SocketAPM(false); + sock = NEW_NOTHROW SocketAPM(false); if (sock != nullptr) { sock->set_blocking(true); thread_create(FUNCTOR_BIND_MEMBER(&AP_Networking::Port::tcp_client_loop, void)); @@ -286,7 +286,7 @@ void AP_Networking::Port::tcp_client_loop(void) hal.scheduler->delay_microseconds(100); } if (sock == nullptr) { - sock = new SocketAPM(false); + sock = NEW_NOTHROW SocketAPM(false); if (sock == nullptr) { continue; } @@ -444,12 +444,12 @@ bool AP_Networking::Port::init_buffers(const uint32_t size_rx, const uint32_t si } WITH_SEMAPHORE(sem); if (readbuffer == nullptr) { - readbuffer = new ByteBuffer(size_rx); + readbuffer = NEW_NOTHROW ByteBuffer(size_rx); } else { readbuffer->set_size_best(size_rx); } if (writebuffer == nullptr) { - writebuffer = new ByteBuffer(size_tx); + writebuffer = NEW_NOTHROW ByteBuffer(size_tx); } else { writebuffer->set_size_best(size_tx); } diff --git a/libraries/AP_Networking/AP_Networking_tests.cpp b/libraries/AP_Networking/AP_Networking_tests.cpp index 839f17f746..4747b0ce88 100644 --- a/libraries/AP_Networking/AP_Networking_tests.cpp +++ b/libraries/AP_Networking/AP_Networking_tests.cpp @@ -43,7 +43,7 @@ void AP_Networking::test_UDP_client(void) startup_wait(); GCS_SEND_TEXT(MAV_SEVERITY_INFO, "UDP_client: starting"); const char *dest = param.test_ipaddr.get_str(); - auto *sock = new SocketAPM(true); + auto *sock = NEW_NOTHROW SocketAPM(true); if (sock == nullptr) { GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "UDP_client: failed to create socket"); return; @@ -75,7 +75,7 @@ void AP_Networking::test_TCP_client(void) startup_wait(); GCS_SEND_TEXT(MAV_SEVERITY_INFO, "TCP_client: starting"); const char *dest = param.test_ipaddr.get_str(); - auto *sock = new SocketAPM(false); + auto *sock = NEW_NOTHROW SocketAPM(false); if (sock == nullptr) { GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "TCP_client: failed to create socket"); return; @@ -107,7 +107,7 @@ void AP_Networking::test_TCP_discard(void) startup_wait(); GCS_SEND_TEXT(MAV_SEVERITY_INFO, "TCP_discard: starting"); const char *dest = param.test_ipaddr.get_str(); - auto *sock = new SocketAPM(false); + auto *sock = NEW_NOTHROW SocketAPM(false); if (sock == nullptr) { GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "TCP_discard: failed to create socket"); return;