Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all clang-tidy warnings #340

Merged
merged 11 commits into from
Oct 26, 2023
Merged

Fix all clang-tidy warnings #340

merged 11 commits into from
Oct 26, 2023

Conversation

stojadin2701
Copy link
Member

No description provided.

@stojadin2701 stojadin2701 force-pushed the combined-patches branch 2 times, most recently from d0113a7 to 59888ca Compare September 16, 2023 16:08
 - Release build on Windows
 - Debug build + linting on Ubuntu
 - Fail workflow if clang-tidy warnings are encountered
@stojadin2701 stojadin2701 marked this pull request as ready for review October 15, 2023 10:13
size_t elem_sz = sizeof(rec_elem.u.gnss_info);
lfs_file_read(&lfs, &curr_file, (uint8_t *)&rec_elem.u.imu, elem_sz);
const size_t elem_sz = sizeof(rec_elem.u.gnss_info);
lfs_file_read(&lfs, &curr_file, reinterpret_cast<uint8_t *>(&rec_elem.u.imu), elem_sz);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were those reinterpret_cast tested? Can you read from the file system?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In general reinterpret_cast doesn't do anything fancy, it's more or less the same as doing a C-style cast, you only declare your intent with this. In this case, we are reinterpreting a pointer to an IMU object to a pointer to uint8_t, which we were already doing.

flight_computer/src/init/config.cpp Show resolved Hide resolved
@@ -224,16 +227,17 @@ void Telemetry::ParseRxMessage(packed_rx_msg_t* rx_payload) noexcept {

PackTxMessage(tick_count, &gnss_data, &tx_payload, estimation_output);

SendTxPayload((uint8_t*)&tx_payload, sizeof(packed_tx_msg_t));
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
SendTxPayload(reinterpret_cast<uint8_t*>(&tx_payload), sizeof(packed_tx_msg_t));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested?

int err = lfs_file_open(&lfs, &curr_file, filename, LFS_O_RDONLY);
if (err) {
const int err = lfs_file_open(&lfs, &curr_file, filename, LFS_O_RDONLY);
if (err < 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= 0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From lfs documentation:

// Returns a negative error code on failure.
int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags);

So we should check for err < 0.

LQmask = (1 << 0);
for (uint8_t i = 0; i < (sizeof(LQArray) / sizeof(LQArray[0])); i++) {
LQmask = (1U << 0U);
for (uint32_t i = 0; i < (sizeof(LQArray) / sizeof(LQArray[0])); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to uint32_t?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because sizeof(LQArray) / sizeof(LQArray[0]) returns an uint32_t element. In reality this doesn't matter as from what I see LQArray's max size is 2, but I didn't want to change the semantics of the line in this patch.

telemetry/src/Gps/Gps.cpp Show resolved Hide resolved
while (busyTransmitting)
;
while (busyTransmitting) {
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt this dangerous?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior is the same both with and without brackets, so it's as dangerous as it was :)

flight_computer/src/config/globals.hpp Outdated Show resolved Hide resolved
flight_computer/src/drivers/buzzer.cpp Outdated Show resolved Hide resolved
@stojadin2701 stojadin2701 self-assigned this Oct 26, 2023
@stojadin2701 stojadin2701 changed the title Combined patches Fix all clang-tidy warnings Oct 26, 2023
@stojadin2701 stojadin2701 merged commit 8208148 into main Oct 26, 2023
10 checks passed
@stojadin2701 stojadin2701 deleted the combined-patches branch October 26, 2023 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants