Skip to content

Conversation

@dakejahl
Copy link
Contributor

@dakejahl dakejahl commented Nov 26, 2025

Dependencies

  sudo apt install clang clang-tidy clang-tools
  sudo ln -s /usr/bin/clang-apply-replacements-14 /usr/bin/clang-apply-replacements

Note: The version number (14) may vary depending on your Ubuntu version. The script will detect the installed version and provide the correct symlink command if needed

Usage

make px4_sitl_default-clang
./Tools/clang_tidy_fix_uninitialized.py src/modules/fw_att_control

@@ -0,0 +1,179 @@
#!/usr/bin/env python3
"""
Fix uninitialized member variables using clang-tidy.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps

Suggested change
Fix uninitialized member variables using clang-tidy.
Initializes uninitialized member variables to 0, using clang-tidy.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to leave the rest of the reviews to the developer team who will actually use this. It's a good idea though, and you might want to update the contribution section of the docs to point to this (and other) tools that are useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it zero initializes primitives and default constructs classes

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps say that then. If you aren't sure that most developers will know why and when you want to do that, perhaps add a note on that too. This is why I suggested adding a link to the contribution section - so that people can find it and know when to use it. Otherwise they'll probably end up manually updating.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mostly opened this PR just to share the solution with Silvan and Mahima, since they just ran into a real bug caused by this. I'll probably leave this open until if/when we decide to fix all of our files.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. I think it might be interesting to add it to CI as a "test" to show uninitialized variables and offer to fix them - give people a chance to spot these cases over time rather than do it as a big-bang. Reasoning being that it's a lot less risky to fix small things than big things.

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