fix(control_allocator): reject negative tilt indices (#29797)

CA_ROTORn_TILT is declared as an enum (0..4), but parameter ranges are
not enforced by param_set(). ActuatorEffectivenessRotors::updateParams()
stores tilt_param - 1 directly, and both consumers only skip the sentinel
value -1. Any value below -1 therefore indexes _params[] and _torque[]
with a negative index, which crashes the control allocator on the next
parameter update.

Treat every negative index as "not tilted" in updateTorqueSign() and
updateAxisFromTilts().

Test: main SITL, CA_AIRFRAME=8 + CA_ROTOR0_TILT=-100000 (SIGSEGV in
ActuatorEffectivenessTilts::updateTorqueSign)


Assisted-by: deepseek

Signed-off-by: Summermu <23356722+Summermu@users.noreply.github.com>
Co-authored-by: Summermu <23356722+Summermu@users.noreply.github.com>
This commit is contained in:
mumumuandSummermu authored and GitHub committed 2026-11-16 16:44:56 -07:00
1 parent d694bf0d53
commit 8638fa397e
2 files changed
+2 -2

No files matched your search

@@ -234,7 +234,7 @@ ActuatorBitmask ActuatorEffectivenessRotors::updateAxisFromTilts(const ActuatorE
for (int i = 0; i < _geometry.num_rotors; ++i) {
int tilt_index = _geometry.rotors[i].tilt_index;
if (tilt_index == -1 || tilt_index >= tilts.count()) {
if (tilt_index < 0 || tilt_index >= tilts.count()) {
nontilted_motors |= 1u << i;
continue;
}
@@ -107,7 +107,7 @@ void ActuatorEffectivenessTilts::updateTorqueSign(const ActuatorEffectivenessRot
for (int i = 0; i < geometry.num_rotors; ++i) {
int tilt_index = geometry.rotors[i].tilt_index;
if (tilt_index == -1 || tilt_index >= _count) {
if (tilt_index < 0 || tilt_index >= _count) {
continue;
}