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:
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 inSimplePacketComs.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: