From 94841dd6084daaedbfba78ac0e4d5fb4ead00bff Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 May 2024 11:24:16 +1000 Subject: [PATCH] Tools: use NEW_NOTHROW for new(std::nothrow) --- Tools/AP_Bootloader/flash_from_sd.cpp | 4 +- Tools/AP_Bootloader/network.cpp | 6 +-- Tools/AP_Periph/AP_Periph.cpp | 2 +- Tools/AP_Periph/GCS_MAVLink.h | 2 +- Tools/AP_Periph/batt_balance.cpp | 6 +-- Tools/AP_Periph/battery.cpp | 4 +- Tools/AP_Periph/can.cpp | 6 +-- Tools/AP_Periph/serial_tunnel.cpp | 2 +- Tools/Replay/LogReader.cpp | 66 +++++++++++++-------------- Tools/Replay/Replay.cpp | 4 +- 10 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Tools/AP_Bootloader/flash_from_sd.cpp b/Tools/AP_Bootloader/flash_from_sd.cpp index c053e48252..9c191a1ae8 100644 --- a/Tools/AP_Bootloader/flash_from_sd.cpp +++ b/Tools/AP_Bootloader/flash_from_sd.cpp @@ -342,7 +342,7 @@ bool flash_from_sd() return false; } - verifier = new ABinVerifier{verify_abin_path}; + verifier = NEW_NOTHROW ABinVerifier{verify_abin_path}; if (!verifier->run()) { goto out; } @@ -354,7 +354,7 @@ bool flash_from_sd() return false; } - flasher = new ABinFlasher{flash_abin_path}; + flasher = NEW_NOTHROW ABinFlasher{flash_abin_path}; if (!flasher->run()) { goto out; } diff --git a/Tools/AP_Bootloader/network.cpp b/Tools/AP_Bootloader/network.cpp index 2a78b199a9..eb47c09ef8 100644 --- a/Tools/AP_Bootloader/network.cpp +++ b/Tools/AP_Bootloader/network.cpp @@ -554,7 +554,7 @@ void BL_Network::net_request_trampoline(void *ctx) */ void BL_Network::web_server(void) { - auto *listen_socket = new SocketAPM(0); + auto *listen_socket = NEW_NOTHROW SocketAPM(0); listen_socket->bind("0.0.0.0", 80); listen_socket->listen(20); @@ -573,7 +573,7 @@ void BL_Network::web_server(void) continue; } // a new thread for each connection to allow for AJAX - auto *req = new req_context; + auto *req = NEW_NOTHROW req_context; req->driver = this; req->sock = sock; thread_create_alloc(THD_WORKING_AREA_SIZE(2048), @@ -601,7 +601,7 @@ void BL_Network::init() macInit(); - thisif = new netif; + thisif = NEW_NOTHROW netif; net_thread_ctx = thread_create_alloc(THD_WORKING_AREA_SIZE(2048), "network", diff --git a/Tools/AP_Periph/AP_Periph.cpp b/Tools/AP_Periph/AP_Periph.cpp index be0d8c32d4..976dbc5834 100644 --- a/Tools/AP_Periph/AP_Periph.cpp +++ b/Tools/AP_Periph/AP_Periph.cpp @@ -268,7 +268,7 @@ void AP_Periph_FW::init() for (uint8_t i = 0; i < ESC_NUMBERS; i++) { const uint8_t port = g.esc_serial_port[i]; if (port < SERIALMANAGER_NUM_PORTS) { // skip bad ports - apd_esc_telem[i] = new ESC_APD_Telem (hal.serial(port), g.pole_count[i]); + apd_esc_telem[i] = NEW_NOTHROW ESC_APD_Telem (hal.serial(port), g.pole_count[i]); } } #endif diff --git a/Tools/AP_Periph/GCS_MAVLink.h b/Tools/AP_Periph/GCS_MAVLink.h index edf5c5f619..fa3366ed11 100644 --- a/Tools/AP_Periph/GCS_MAVLink.h +++ b/Tools/AP_Periph/GCS_MAVLink.h @@ -61,7 +61,7 @@ protected: GCS_MAVLINK_Periph *new_gcs_mavlink_backend(GCS_MAVLINK_Parameters ¶ms, AP_HAL::UARTDriver &uart) override { - return new GCS_MAVLINK_Periph(params, uart); + return NEW_NOTHROW GCS_MAVLINK_Periph(params, uart); } private: diff --git a/Tools/AP_Periph/batt_balance.cpp b/Tools/AP_Periph/batt_balance.cpp index 86c7c7a11c..e7869e01b4 100644 --- a/Tools/AP_Periph/batt_balance.cpp +++ b/Tools/AP_Periph/batt_balance.cpp @@ -80,7 +80,7 @@ void AP_Periph_FW::batt_balance_update() // allocate cell sources if needed if (battery_balance.cells == nullptr) { - battery_balance.cells = new AP_HAL::AnalogSource*[ncell]; + battery_balance.cells = NEW_NOTHROW AP_HAL::AnalogSource*[ncell]; if (battery_balance.cells == nullptr) { return; } @@ -98,8 +98,8 @@ void AP_Periph_FW::batt_balance_update() // allocate space for the packet. This is a large // packet that won't fit on the stack, so dynamically allocate - auto *pkt = new ardupilot_equipment_power_BatteryInfoAux; - uint8_t *buffer = new uint8_t[ARDUPILOT_EQUIPMENT_POWER_BATTERYINFOAUX_MAX_SIZE]; + auto *pkt = NEW_NOTHROW ardupilot_equipment_power_BatteryInfoAux; + uint8_t *buffer = NEW_NOTHROW uint8_t[ARDUPILOT_EQUIPMENT_POWER_BATTERYINFOAUX_MAX_SIZE]; if (pkt == nullptr || buffer == nullptr) { delete pkt; delete [] buffer; diff --git a/Tools/AP_Periph/battery.cpp b/Tools/AP_Periph/battery.cpp index 8f07834d22..442109951f 100644 --- a/Tools/AP_Periph/battery.cpp +++ b/Tools/AP_Periph/battery.cpp @@ -90,8 +90,8 @@ void AP_Periph_FW::can_battery_send_cells(uint8_t instance) { // allocate space for the packet. This is a large // packet that won't fit on the stack, so dynamically allocate - auto* pkt = new ardupilot_equipment_power_BatteryInfoAux; - uint8_t* buffer = new uint8_t[ARDUPILOT_EQUIPMENT_POWER_BATTERYINFOAUX_MAX_SIZE]; + auto* pkt = NEW_NOTHROW ardupilot_equipment_power_BatteryInfoAux; + uint8_t* buffer = NEW_NOTHROW uint8_t[ARDUPILOT_EQUIPMENT_POWER_BATTERYINFOAUX_MAX_SIZE]; if (pkt == nullptr || buffer == nullptr) { delete pkt; delete [] buffer; diff --git a/Tools/AP_Periph/can.cpp b/Tools/AP_Periph/can.cpp index 1b5607cdab..110a482f2f 100644 --- a/Tools/AP_Periph/can.cpp +++ b/Tools/AP_Periph/can.cpp @@ -1622,15 +1622,15 @@ void AP_Periph_FW::can_start() for (uint8_t i=0; i (HAL_PERIPH_CAN_MIRROR_QUEUE_SIZE); + instances[i].mirror_queue = NEW_NOTHROW ObjectBuffer (HAL_PERIPH_CAN_MIRROR_QUEUE_SIZE); } #endif //HAL_PERIPH_CAN_MIRROR #if HAL_NUM_CAN_IFACES >= 2 diff --git a/Tools/AP_Periph/serial_tunnel.cpp b/Tools/AP_Periph/serial_tunnel.cpp index 6a99126980..758f51ca51 100644 --- a/Tools/AP_Periph/serial_tunnel.cpp +++ b/Tools/AP_Periph/serial_tunnel.cpp @@ -79,7 +79,7 @@ void AP_Periph_FW::handle_tunnel_Targetted(CanardInstance* canard_ins, CanardRxT return; } if (uart_monitor.buffer == nullptr) { - uart_monitor.buffer = new ByteBuffer(1024); + uart_monitor.buffer = NEW_NOTHROW ByteBuffer(1024); if (uart_monitor.buffer == nullptr) { return; } diff --git a/Tools/Replay/LogReader.cpp b/Tools/Replay/LogReader.cpp index 9a84053ab8..7c1b1a4394 100644 --- a/Tools/Replay/LogReader.cpp +++ b/Tools/Replay/LogReader.cpp @@ -61,71 +61,71 @@ bool LogReader::handle_log_format_msg(const struct log_Format &f) // map from format name to a parser subclass: if (streq(name, "PARM")) { - msgparser[f.type] = new LR_MsgHandler_PARM(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_PARM(formats[f.type]); } else if (streq(name, "RFRH")) { - msgparser[f.type] = new LR_MsgHandler_RFRH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RFRH(formats[f.type]); } else if (streq(name, "RFRF")) { - msgparser[f.type] = new LR_MsgHandler_RFRF(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RFRF(formats[f.type], ekf2, ekf3); } else if (streq(name, "RFRN")) { - msgparser[f.type] = new LR_MsgHandler_RFRN(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RFRN(formats[f.type]); } else if (streq(name, "REV2")) { - msgparser[f.type] = new LR_MsgHandler_REV2(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REV2(formats[f.type], ekf2, ekf3); } else if (streq(name, "RSO2")) { - msgparser[f.type] = new LR_MsgHandler_RSO2(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RSO2(formats[f.type], ekf2, ekf3); } else if (streq(name, "RWA2")) { - msgparser[f.type] = new LR_MsgHandler_RWA2(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RWA2(formats[f.type], ekf2, ekf3); } else if (streq(name, "REV3")) { - msgparser[f.type] = new LR_MsgHandler_REV3(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REV3(formats[f.type], ekf2, ekf3); } else if (streq(name, "RSO3")) { - msgparser[f.type] = new LR_MsgHandler_RSO3(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RSO3(formats[f.type], ekf2, ekf3); } else if (streq(name, "RWA3")) { - msgparser[f.type] = new LR_MsgHandler_RWA3(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RWA3(formats[f.type], ekf2, ekf3); } else if (streq(name, "REY3")) { - msgparser[f.type] = new LR_MsgHandler_REY3(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REY3(formats[f.type], ekf2, ekf3); } else if (streq(name, "RISH")) { - msgparser[f.type] = new LR_MsgHandler_RISH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RISH(formats[f.type]); } else if (streq(name, "RISI")) { - msgparser[f.type] = new LR_MsgHandler_RISI(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RISI(formats[f.type]); } else if (streq(name, "RASH")) { - msgparser[f.type] = new LR_MsgHandler_RASH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RASH(formats[f.type]); } else if (streq(name, "RASI")) { - msgparser[f.type] = new LR_MsgHandler_RASI(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RASI(formats[f.type]); } else if (streq(name, "RBRH")) { - msgparser[f.type] = new LR_MsgHandler_RBRH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBRH(formats[f.type]); } else if (streq(name, "RBRI")) { - msgparser[f.type] = new LR_MsgHandler_RBRI(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBRI(formats[f.type]); } else if (streq(name, "RRNH")) { - msgparser[f.type] = new LR_MsgHandler_RRNH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RRNH(formats[f.type]); } else if (streq(name, "RRNI")) { - msgparser[f.type] = new LR_MsgHandler_RRNI(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RRNI(formats[f.type]); } else if (streq(name, "RGPH")) { - msgparser[f.type] = new LR_MsgHandler_RGPH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RGPH(formats[f.type]); } else if (streq(name, "RGPI")) { - msgparser[f.type] = new LR_MsgHandler_RGPI(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RGPI(formats[f.type]); } else if (streq(name, "RGPJ")) { - msgparser[f.type] = new LR_MsgHandler_RGPJ(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RGPJ(formats[f.type]); } else if (streq(name, "RMGH")) { - msgparser[f.type] = new LR_MsgHandler_RMGH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RMGH(formats[f.type]); } else if (streq(name, "RMGI")) { - msgparser[f.type] = new LR_MsgHandler_RMGI(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RMGI(formats[f.type]); } else if (streq(name, "RBCH")) { - msgparser[f.type] = new LR_MsgHandler_RBCH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBCH(formats[f.type]); } else if (streq(name, "RBCI")) { - msgparser[f.type] = new LR_MsgHandler_RBCI(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBCI(formats[f.type]); } else if (streq(name, "RVOH")) { - msgparser[f.type] = new LR_MsgHandler_RVOH(formats[f.type]); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RVOH(formats[f.type]); } else if (streq(name, "ROFH")) { - msgparser[f.type] = new LR_MsgHandler_ROFH(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_ROFH(formats[f.type], ekf2, ekf3); } else if (streq(name, "REPH")) { - msgparser[f.type] = new LR_MsgHandler_REPH(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REPH(formats[f.type], ekf2, ekf3); } else if (streq(name, "RSLL")) { - msgparser[f.type] = new LR_MsgHandler_RSLL(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RSLL(formats[f.type], ekf2, ekf3); } else if (streq(name, "REVH")) { - msgparser[f.type] = new LR_MsgHandler_REVH(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_REVH(formats[f.type], ekf2, ekf3); } else if (streq(name, "RWOH")) { - msgparser[f.type] = new LR_MsgHandler_RWOH(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RWOH(formats[f.type], ekf2, ekf3); } else if (streq(name, "RBOH")) { - msgparser[f.type] = new LR_MsgHandler_RBOH(formats[f.type], ekf2, ekf3); + msgparser[f.type] = NEW_NOTHROW LR_MsgHandler_RBOH(formats[f.type], ekf2, ekf3); } else { // debug(" No parser for (%s)\n", name); } diff --git a/Tools/Replay/Replay.cpp b/Tools/Replay/Replay.cpp index d3dc533979..2166885e4d 100644 --- a/Tools/Replay/Replay.cpp +++ b/Tools/Replay/Replay.cpp @@ -161,7 +161,7 @@ void Replay::_parse_command_line(uint8_t argc, char * const argv[]) ::printf("Usage: -p NAME=VALUE\n"); exit(1); } - struct user_parameter *u = new user_parameter; + struct user_parameter *u = NEW_NOTHROW user_parameter; strncpy(u->name, gopt.optarg, eq-gopt.optarg); u->value = atof(eq+1); u->next = user_parameters; @@ -310,7 +310,7 @@ void Replay::load_param_file(const char *pfilename) if (!parse_param_line(line, &pname, value)) { continue; } - struct user_parameter *u = new user_parameter; + struct user_parameter *u = NEW_NOTHROW user_parameter; strncpy_noterm(u->name, pname, sizeof(u->name)); u->value = value; u->next = user_parameters;