Check vector lengths at runtime to prevent undefined behaviour (#23)
This commit is contained in:
parent
5b2fbb028c
commit
4478a105d8
@ -31,6 +31,13 @@ OpenArm::OpenArm(const std::string& can_interface, bool enable_fd)
|
|||||||
void OpenArm::init_arm_motors(const std::vector<damiao_motor::MotorType>& motor_types,
|
void OpenArm::init_arm_motors(const std::vector<damiao_motor::MotorType>& motor_types,
|
||||||
const std::vector<uint32_t>& send_can_ids,
|
const std::vector<uint32_t>& send_can_ids,
|
||||||
const std::vector<uint32_t>& recv_can_ids) {
|
const std::vector<uint32_t>& recv_can_ids) {
|
||||||
|
if (motor_types.size() != send_can_ids.size() || motor_types.size() != recv_can_ids.size()) {
|
||||||
|
throw std::invalid_argument(
|
||||||
|
"Motor types, send CAN IDs, and receive CAN IDs vectors must have the same size, "
|
||||||
|
"currently: " +
|
||||||
|
std::to_string(motor_types.size()) + ", " + std::to_string(send_can_ids.size()) + ", " +
|
||||||
|
std::to_string(recv_can_ids.size()));
|
||||||
|
}
|
||||||
arm_->init_motor_devices(motor_types, send_can_ids, recv_can_ids, enable_fd_);
|
arm_->init_motor_devices(motor_types, send_can_ids, recv_can_ids, enable_fd_);
|
||||||
register_dm_device_collection(*arm_);
|
register_dm_device_collection(*arm_);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user