mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 04:53:33 +08:00
CI: enable clang-tidy bugprone-assignment-in-if-condition (#26580)
* docs: auto-sync metadata [skip ci] Co-Authored-By: PX4 BuildBot <bot@px4.io> CI: enable clang-tidy bugprone-assignment-in-if-condition Signed-off-by: kuralme <kuralme@protonmail.com> initialize and immediate assignments made one line Signed-off-by: kuralme <kuralme@protonmail.com> * two more initialization fix Signed-off-by: kuralme <kuralme@protonmail.com> --------- Signed-off-by: kuralme <kuralme@protonmail.com> Co-authored-by: PX4BuildBot <bot@px4.io>
This commit is contained in:
co-authored by
PX4 BuildBot
parent
c424edd055
commit
d317113dc8
@@ -149,7 +149,6 @@ Checks: '*,
|
|||||||
-cppcoreguidelines-explicit-virtual-functions,
|
-cppcoreguidelines-explicit-virtual-functions,
|
||||||
-readability-convert-member-functions-to-static,
|
-readability-convert-member-functions-to-static,
|
||||||
-readability-make-member-function-const,
|
-readability-make-member-function-const,
|
||||||
-bugprone-assignment-in-if-condition,
|
|
||||||
-bugprone-implicit-widening-of-multiplication-result,
|
-bugprone-implicit-widening-of-multiplication-result,
|
||||||
-bugprone-macro-parentheses,
|
-bugprone-macro-parentheses,
|
||||||
-bugprone-multi-level-implicit-pointer-conversion,
|
-bugprone-multi-level-implicit-pointer-conversion,
|
||||||
|
|||||||
@@ -941,10 +941,10 @@ int uORBTest::UnitTest::pub_test_queue_entry(int argc, char *argv[])
|
|||||||
int uORBTest::UnitTest::pub_test_queue_main()
|
int uORBTest::UnitTest::pub_test_queue_main()
|
||||||
{
|
{
|
||||||
orb_test_medium_s t{};
|
orb_test_medium_s t{};
|
||||||
orb_advert_t ptopic{nullptr};
|
orb_advert_t ptopic = orb_advertise(ORB_ID(orb_test_medium_queue_poll), &t);
|
||||||
const int queue_size = orb_get_queue_size(ORB_ID(orb_test_medium_queue_poll));
|
const int queue_size = orb_get_queue_size(ORB_ID(orb_test_medium_queue_poll));
|
||||||
|
|
||||||
if ((ptopic = orb_advertise(ORB_ID(orb_test_medium_queue_poll), &t)) == nullptr) {
|
if (ptopic == nullptr) {
|
||||||
_thread_should_exit = true;
|
_thread_should_exit = true;
|
||||||
return test_fail("advertise failed: %d", errno);
|
return test_fail("advertise failed: %d", errno);
|
||||||
}
|
}
|
||||||
@@ -981,9 +981,9 @@ int uORBTest::UnitTest::test_queue_poll_notify()
|
|||||||
test_note("Testing orb queuing (poll & notify)");
|
test_note("Testing orb queuing (poll & notify)");
|
||||||
|
|
||||||
orb_test_medium_s t{};
|
orb_test_medium_s t{};
|
||||||
int sfd = -1;
|
int sfd = orb_subscribe(ORB_ID(orb_test_medium_queue_poll));
|
||||||
|
|
||||||
if ((sfd = orb_subscribe(ORB_ID(orb_test_medium_queue_poll))) < 0) {
|
if (sfd < 0) {
|
||||||
return test_fail("subscribe failed: %d", errno);
|
return test_fail("subscribe failed: %d", errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -128,10 +128,10 @@ bool SerialImpl::configure()
|
|||||||
|
|
||||||
struct termios uart_config;
|
struct termios uart_config;
|
||||||
|
|
||||||
int termios_state;
|
int termios_state = tcgetattr(_serial_fd, &uart_config);
|
||||||
|
|
||||||
/* fill the struct for the new configuration */
|
/* fill the struct for the new configuration */
|
||||||
if ((termios_state = tcgetattr(_serial_fd, &uart_config)) < 0) {
|
if (termios_state < 0) {
|
||||||
PX4_ERR("ERR: %d (tcgetattr)", termios_state);
|
PX4_ERR("ERR: %d (tcgetattr)", termios_state);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -199,17 +199,23 @@ bool SerialImpl::configure()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set baud rate */
|
/* set baud rate */
|
||||||
if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) {
|
termios_state = cfsetispeed(&uart_config, speed);
|
||||||
|
|
||||||
|
if (termios_state < 0) {
|
||||||
PX4_ERR("ERR: %d (cfsetispeed)", termios_state);
|
PX4_ERR("ERR: %d (cfsetispeed)", termios_state);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) {
|
termios_state = cfsetospeed(&uart_config, speed);
|
||||||
|
|
||||||
|
if (termios_state < 0) {
|
||||||
PX4_ERR("ERR: %d (cfsetospeed)", termios_state);
|
PX4_ERR("ERR: %d (cfsetospeed)", termios_state);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((termios_state = tcsetattr(_serial_fd, TCSANOW, &uart_config)) < 0) {
|
termios_state = tcsetattr(_serial_fd, TCSANOW, &uart_config);
|
||||||
|
|
||||||
|
if (termios_state < 0) {
|
||||||
PX4_ERR("ERR: %d (tcsetattr)", termios_state);
|
PX4_ERR("ERR: %d (tcsetattr)", termios_state);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,9 +209,9 @@ void Pxh::run_remote_pxh(int remote_in_fd, int remote_out_fd)
|
|||||||
if (fds[0].revents & POLLIN) {
|
if (fds[0].revents & POLLIN) {
|
||||||
|
|
||||||
uint8_t buffer[512];
|
uint8_t buffer[512];
|
||||||
size_t len;
|
size_t len = read(pipe_stderr, buffer, sizeof(buffer));
|
||||||
|
|
||||||
if ((len = read(pipe_stderr, buffer, sizeof(buffer))) <= 0) {
|
if (len <= 0) {
|
||||||
break; //EOF or ERROR
|
break; //EOF or ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,9 +233,9 @@ void Pxh::run_remote_pxh(int remote_in_fd, int remote_out_fd)
|
|||||||
if (fds[1].revents & POLLIN) {
|
if (fds[1].revents & POLLIN) {
|
||||||
|
|
||||||
uint8_t buffer[512];
|
uint8_t buffer[512];
|
||||||
size_t len;
|
size_t len = read(pipe_stdout, buffer, sizeof(buffer));
|
||||||
|
|
||||||
if ((len = read(pipe_stdout, buffer, sizeof(buffer))) <= 0) {
|
if (len <= 0) {
|
||||||
break; //EOF or ERROR
|
break; //EOF or ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -269,9 +269,9 @@ void
|
|||||||
cmd.pop_back();
|
cmd.pop_back();
|
||||||
|
|
||||||
// We register thread specific data. This is used for PX4_INFO (etc.) log calls.
|
// We register thread specific data. This is used for PX4_INFO (etc.) log calls.
|
||||||
CmdThreadSpecificData *thread_data_ptr;
|
CmdThreadSpecificData *thread_data_ptr = static_cast<CmdThreadSpecificData *>(pthread_getspecific(_instance->_key));
|
||||||
|
|
||||||
if ((thread_data_ptr = (CmdThreadSpecificData *)pthread_getspecific(_instance->_key)) == nullptr) {
|
if (thread_data_ptr == nullptr) {
|
||||||
thread_data_ptr = new CmdThreadSpecificData;
|
thread_data_ptr = new CmdThreadSpecificData;
|
||||||
thread_data_ptr->thread_stdout = out;
|
thread_data_ptr->thread_stdout = out;
|
||||||
thread_data_ptr->is_atty = isatty;
|
thread_data_ptr->is_atty = isatty;
|
||||||
|
|||||||
@@ -60,20 +60,20 @@ using namespace px4_daemon;
|
|||||||
|
|
||||||
FILE *get_stdout(bool *isatty_)
|
FILE *get_stdout(bool *isatty_)
|
||||||
{
|
{
|
||||||
Server::CmdThreadSpecificData *thread_data_ptr;
|
// If the server is not running, we are not in a thread that has been started
|
||||||
|
if (!Server::is_running()) {
|
||||||
// If we are not in a thread that has been started by a client, we don't
|
|
||||||
// have any thread specific data set and we won't have a pipe to write
|
|
||||||
// stdout to.
|
|
||||||
if (!Server::is_running() ||
|
|
||||||
(thread_data_ptr = (Server::CmdThreadSpecificData *)pthread_getspecific(
|
|
||||||
Server::get_pthread_key())) == nullptr) {
|
|
||||||
if (isatty_) { *isatty_ = isatty(1); }
|
if (isatty_) { *isatty_ = isatty(1); }
|
||||||
|
|
||||||
return stdout;
|
return stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread_data_ptr->thread_stdout == nullptr) {
|
Server::CmdThreadSpecificData *thread_data_ptr = static_cast<Server::CmdThreadSpecificData *>(pthread_getspecific(
|
||||||
|
Server::get_pthread_key()));
|
||||||
|
|
||||||
|
// If we are not in a thread that has been started by a client, we don't
|
||||||
|
// have any thread specific data set and we won't have a pipe to write
|
||||||
|
// stdout to.
|
||||||
|
if (thread_data_ptr == nullptr || thread_data_ptr->thread_stdout == nullptr) {
|
||||||
if (isatty_) { *isatty_ = isatty(1); }
|
if (isatty_) { *isatty_ = isatty(1); }
|
||||||
|
|
||||||
return stdout;
|
return stdout;
|
||||||
|
|||||||
@@ -170,7 +170,9 @@ int MspV1::Receive(uint8_t *payload, uint8_t *message_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (bytes_available > 4) {
|
while (bytes_available > 4) {
|
||||||
if ((ret = read(_fd, header, 1)) != 1) {
|
ret = read(_fd, header, 1);
|
||||||
|
|
||||||
|
if (ret != 1) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +188,9 @@ int MspV1::Receive(uint8_t *payload, uint8_t *message_id)
|
|||||||
return -EWOULDBLOCK;
|
return -EWOULDBLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = read(_fd, &header[1], 4)) != 4) {
|
ret = read(_fd, &header[1], 4);
|
||||||
|
|
||||||
|
if (ret != 4) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +202,9 @@ int MspV1::Receive(uint8_t *payload, uint8_t *message_id)
|
|||||||
payload_size = header[3];
|
payload_size = header[3];
|
||||||
*message_id = header[4];
|
*message_id = header[4];
|
||||||
|
|
||||||
if ((ret = read(_fd, payload, payload_size + MSP_CRC_SIZE)) != payload_size + MSP_CRC_SIZE) {
|
ret = read(_fd, payload, payload_size + MSP_CRC_SIZE);
|
||||||
|
|
||||||
|
if (ret != payload_size + MSP_CRC_SIZE) {
|
||||||
if (ret != -EWOULDBLOCK) {
|
if (ret != -EWOULDBLOCK) {
|
||||||
has_header = false;
|
has_header = false;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -161,7 +161,9 @@ int LedController::update(LedControlData &control_data)
|
|||||||
if (current_blink_duration > 0) {
|
if (current_blink_duration > 0) {
|
||||||
++num_blinking_leds;
|
++num_blinking_leds;
|
||||||
|
|
||||||
if ((_states[i].current_blinking_time += blink_delta_t) > current_blink_duration) {
|
_states[i].current_blinking_time += blink_delta_t;
|
||||||
|
|
||||||
|
if (_states[i].current_blinking_time > current_blink_duration) {
|
||||||
_states[i].current_blinking_time -= current_blink_duration;
|
_states[i].current_blinking_time -= current_blink_duration;
|
||||||
|
|
||||||
if (cur_data.blink_times_left == 246) {
|
if (cur_data.blink_times_left == 246) {
|
||||||
|
|||||||
@@ -182,7 +182,9 @@ InputMavlinkCmdMount::~InputMavlinkCmdMount()
|
|||||||
|
|
||||||
int InputMavlinkCmdMount::initialize()
|
int InputMavlinkCmdMount::initialize()
|
||||||
{
|
{
|
||||||
if ((_vehicle_command_sub = orb_subscribe(ORB_ID(vehicle_command))) < 0) {
|
_vehicle_command_sub = orb_subscribe(ORB_ID(vehicle_command));
|
||||||
|
|
||||||
|
if (_vehicle_command_sub < 0) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,11 +440,15 @@ int InputMavlinkGimbalV2::initialize()
|
|||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_vehicle_command_sub = orb_subscribe(ORB_ID(vehicle_command))) < 0) {
|
_vehicle_command_sub = orb_subscribe(ORB_ID(vehicle_command));
|
||||||
|
|
||||||
|
if (_vehicle_command_sub < 0) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((_gimbal_manager_set_manual_control_sub = orb_subscribe(ORB_ID(gimbal_manager_set_manual_control))) < 0) {
|
_gimbal_manager_set_manual_control_sub = orb_subscribe(ORB_ID(gimbal_manager_set_manual_control));
|
||||||
|
|
||||||
|
if (_gimbal_manager_set_manual_control_sub < 0) {
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1120,7 +1120,9 @@ void SimulatorMavlink::run()
|
|||||||
|
|
||||||
if (_ip == InternetProtocol::UDP) {
|
if (_ip == InternetProtocol::UDP) {
|
||||||
|
|
||||||
if ((_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
|
||||||
|
if (_fd < 0) {
|
||||||
PX4_ERR("Creating UDP socket failed: %s", strerror(errno));
|
PX4_ERR("Creating UDP socket failed: %s", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1153,7 +1155,9 @@ void SimulatorMavlink::run()
|
|||||||
PX4_INFO("Waiting for simulator to accept connection on TCP port %u", _port);
|
PX4_INFO("Waiting for simulator to accept connection on TCP port %u", _port);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if ((_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
|
||||||
|
if (_fd < 0) {
|
||||||
PX4_ERR("Creating TCP socket failed: %s", strerror(errno));
|
PX4_ERR("Creating TCP socket failed: %s", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -851,17 +851,23 @@ bool UxrceddsClient::setBaudrate(int fd, unsigned baud)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set baud rate */
|
/* set baud rate */
|
||||||
if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) {
|
termios_state = cfsetispeed(&uart_config, speed);
|
||||||
|
|
||||||
|
if (termios_state < 0) {
|
||||||
PX4_ERR("ERR: %d (cfsetispeed)", termios_state);
|
PX4_ERR("ERR: %d (cfsetispeed)", termios_state);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) {
|
termios_state = cfsetospeed(&uart_config, speed);
|
||||||
|
|
||||||
|
if (termios_state < 0) {
|
||||||
PX4_ERR("ERR: %d (cfsetospeed)", termios_state);
|
PX4_ERR("ERR: %d (cfsetospeed)", termios_state);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((termios_state = tcsetattr(fd, TCSANOW, &uart_config)) < 0) {
|
termios_state = tcsetattr(fd, TCSANOW, &uart_config);
|
||||||
|
|
||||||
|
if (termios_state < 0) {
|
||||||
PX4_ERR("ERR: %d (tcsetattr)", termios_state);
|
PX4_ERR("ERR: %d (tcsetattr)", termios_state);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user