WPIRoboticsEngineering / RBE3001_nucleo_firmware

Sample firmware for the RBE 3001 arm
6 stars 20 forks source link

Fix of incorrect packet clear #20

Closed MikaylaFischler closed 6 years ago

MikaylaFischler commented 6 years ago
for (int i = 4; i < 64; i++)
      buff[i] = 0;

The above code (starting at PidServer.cpp:87) assumes packet is a pointer to the first value in the 64 byte packet response, but the event function is provided a pointer to the data (with a per-existing 4-byte offset) as shown in SimplePacketComs.cpp:31:

(*it)->event(getDataPointer());

Therefore, the code above doesn't overwrite the first 4 bytes of data (in addition to not touching the ID) but does overwrite 4 bytes of other memory after the packet, which could contain any other variable depending on how the compiler ordered them in memory. The code should be as follows to avoid unexpected behavior:

for (int i = 0; i < 60; i++)
      buff[i] = 0;
madhephaestus commented 6 years ago

good chatch