IO driver: Ensure comms protocol cannot get into integer overflow on bad control outputs. Fixes #2119.

This commit is contained in:
Lorenz Meier
2015-05-04 14:58:57 +02:00
parent 980d9bcf3e
commit e09f5d2871
+11 -1
View File
@@ -1181,7 +1181,17 @@ PX4IO::io_set_control_state(unsigned group)
}
for (unsigned i = 0; i < _max_controls; i++) {
regs[i] = FLOAT_TO_REG(controls.control[i]);
/* ensure FLOAT_TO_REG does not produce an integer overflow */
float ctrl = controls.control[i];
if (ctrl < -1.0f) {
ctrl = -1.0f;
} else if (ctrl > 1.0f) {
ctrl = 1.0f;
}
regs[i] = FLOAT_TO_REG(ctrl);
}
/* copy values to registers in IO */