autowp / arduino-mcp2515

Arduino MCP2515 CAN interface library
MIT License
795 stars 279 forks source link

Structure alignment #107

Open netlcod opened 9 months ago

netlcod commented 9 months ago

I think the can_frame structure needs alignment added. This is necessary for cases when CAN commands are sent streaming (Serial, for example).

#pragma pack(push,1)
struct can_frame {
    canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
    __u8    can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
    __u8    data[CAN_MAX_DLEN] __attribute__((aligned(8)));
};
#pragma pack(pop)

Field sizes are 4b + 1b + 8b = 13b. Struct size is 16b without alignment.