Skip to content

Fix -Wvla warnings in dynamixel_workbench_toolbox #63

Description

@Eric-SHENNONGSHI

What happened

Building dynamixel_workbench_toolbox (ROS 2 Humble, GCC on Ubuntu 22.04, default -Wall -Wextra -Wpedantic-style flags via colcon) emits two -Wvla warnings:

dynamixel_workbench_toolbox/src/dynamixel_workbench_toolbox/dynamixel_driver.cpp: In member function ‘bool DynamixelDriver::readRegister(uint8_t, uint16_t, uint16_t, uint32_t*, const char**)’:
dynamixel_driver.cpp:776:11: warning: ISO C++ forbids variable length array ‘data_read’ [-Wvla]
  776 |   uint8_t data_read[length];
      |           ^~~~~~~~~

dynamixel_driver.cpp: In member function ‘bool DynamixelDriver::syncWrite(uint8_t, uint8_t*, uint8_t, int32_t*, uint8_t, const char**)’:
dynamixel_driver.cpp:1012:11: warning: ISO C++ forbids variable length array ‘multi_parameter’ [-Wvla]
 1012 |   uint8_t multi_parameter[4*data_num_for_each_id];
      |           ^~~~~~~~~~~~~~~

The same code is present on main at lines 772 and 1009 of
interbotix_ros_xseries/dynamixel_workbench_toolbox/src/dynamixel_workbench_toolbox/dynamixel_driver.cpp.

Why it matters

Variable-length arrays are a C99 feature, not part of any C++ standard; GCC only accepts them as an extension. Besides the warning noise in every downstream build (colcon surfaces the package under a --- stderr: block), a large runtime length can silently overflow the stack.

Suggested fix

Replace the VLAs with std::vector<uint8_t>:

std::vector<uint8_t> data_read(length);
...
std::vector<uint8_t> multi_parameter(4 * data_num_for_each_id);

The buffers are passed to the Dynamixel SDK as uint8_t*, so data_read.data() drops in without further changes.

Happy to open a PR if the fix is welcome.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions