Check vector lengths at runtime to prevent undefined behaviour (#23)

This commit is contained in:
thomason 2025-08-29 18:37:39 +09:00 committed by GitHub
parent 5b2fbb028c
commit 4478a105d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,
const std::vector<uint32_t>& send_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_);
register_dm_device_collection(*arm_);
}