From 113853f6316b39caf593ec9bf0eb67ef82dda18f Mon Sep 17 00:00:00 2001 From: Ege Kural Date: Mon, 16 Mar 2026 17:59:06 -0400 Subject: [PATCH] fix(ci): enable clang-tidy bugprone-unhandled-self-assignment / cert-oop54-cpp (#26767) Signed-off-by: kuralme --- .clang-tidy | 2 -- platforms/common/uORB/Subscription.hpp | 5 +++++ src/lib/lat_lon_alt/lat_lon_alt.hpp | 5 +++++ src/lib/matrix/matrix/Slice.hpp | 5 +++++ .../ekf2/EKF/bias_estimator/position_bias_estimator.hpp | 2 +- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 3c4757dfef..80bea547df 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -141,8 +141,6 @@ Checks: '*, -cppcoreguidelines-avoid-goto, -hicpp-avoid-goto, -bugprone-branch-clone, - -bugprone-unhandled-self-assignment, - -cert-oop54-cpp, -performance-enum-size, -readability-avoid-nested-conditional-operator, -cppcoreguidelines-prefer-member-initializer, diff --git a/platforms/common/uORB/Subscription.hpp b/platforms/common/uORB/Subscription.hpp index 723427d840..e899762751 100644 --- a/platforms/common/uORB/Subscription.hpp +++ b/platforms/common/uORB/Subscription.hpp @@ -92,6 +92,11 @@ public: // copy assignment Subscription &operator=(const Subscription &other) { + // Check for self-assignment + if (this == &other) { + return *this; + } + unsubscribe(); _orb_id = other._orb_id; _instance = other._instance; diff --git a/src/lib/lat_lon_alt/lat_lon_alt.hpp b/src/lib/lat_lon_alt/lat_lon_alt.hpp index 02614c1862..e72fc5fa79 100644 --- a/src/lib/lat_lon_alt/lat_lon_alt.hpp +++ b/src/lib/lat_lon_alt/lat_lon_alt.hpp @@ -87,6 +87,11 @@ public: void operator=(const LatLonAlt &lla) { + // Protect against self-assignment + if (this == &lla) { + return; + } + _latitude_rad = lla.latitude_rad(); _longitude_rad = lla.longitude_rad(); _altitude = lla.altitude(); diff --git a/src/lib/matrix/matrix/Slice.hpp b/src/lib/matrix/matrix/Slice.hpp index 53d24769e9..e4c14da4f0 100644 --- a/src/lib/matrix/matrix/Slice.hpp +++ b/src/lib/matrix/matrix/Slice.hpp @@ -59,6 +59,11 @@ public: // Separate function needed otherwise the default copy constructor matches before the deep copy implementation Self &operator=(const Self &other) { + // Protect against self-assignment + if (this == &other) { + return *this; + } + return this->operator=(other); } diff --git a/src/modules/ekf2/EKF/bias_estimator/position_bias_estimator.hpp b/src/modules/ekf2/EKF/bias_estimator/position_bias_estimator.hpp index 629bb538a1..6d8a5e2213 100644 --- a/src/modules/ekf2/EKF/bias_estimator/position_bias_estimator.hpp +++ b/src/modules/ekf2/EKF/bias_estimator/position_bias_estimator.hpp @@ -62,7 +62,7 @@ public: } } - void fuseBias(Vector2f bias, Vector2f bias_var) + void fuseBias(const Vector2f &bias, const Vector2f &bias_var) { if ((_sensor_ref != _sensor) && _is_sensor_fusion_active) { _bias[0].fuseBias(bias(0), bias_var(0));