Fix address-of-packed-member warnings

GCC9 introduced an address-of-packed-member warning that triggers in
esc_coe.c. The issue is that a packed struct has an overall alignment
of 1, and taking the address of a member in a packed struct is not
guaranteed to have any particular alignment. However, in esc_coe these
structs are always overlayed on aligned memory so in practice there is
no problem.

Fix the problem by explicitly setting the minimum alignment for the
structs used in this manner. Also fix an instance where an unaligned
pointer was used but never dereferenced (by changing the type of the
pointer from uint32_t* to void*).
pull/106/head
Hans-Erik Floryd 2021-10-25 13:33:01 +02:00
parent 4d9da268be
commit 097477035d
3 changed files with 5 additions and 4 deletions

View File

@ -573,7 +573,7 @@ typedef struct CC_PACKED
CC_PACKED_END
CC_PACKED_BEGIN
typedef struct CC_PACKED
typedef struct CC_PACKED CC_ALIGNED(4)
{
_MBXh mbxheader;
_COEh coeheader;
@ -585,7 +585,7 @@ typedef struct CC_PACKED
CC_PACKED_END
CC_PACKED_BEGIN
typedef struct CC_PACKED
typedef struct CC_PACKED CC_ALIGNED(4)
{
_MBXh mbxheader;
_COEh coeheader;

View File

@ -1022,8 +1022,8 @@ static void SDO_downloadsegment (void)
(coesdo->command & COE_TOGGLEBIT); /* copy toggle bit */
init_coesdo(coeres, COE_SDORESPONSE, command, 0, 0);
uint32_t *mbxdata = (uint32_t *)&(coesdo->index); /* data pointer */
copy2mbx (mbxdata, (uint8_t *)ESCvar.data, size);
void *mbxdata = &(coesdo->index); /* data pointer */
copy2mbx (mbxdata, ESCvar.data, size);
if (coesdo->command & COE_COMMAND_LASTSEGMENTBIT)
{

View File

@ -32,6 +32,7 @@ extern "C"
#define CC_PACKED_BEGIN
#define CC_PACKED_END
#define CC_PACKED __attribute__((packed))
#define CC_ALIGNED(n) __attribute__((aligned (n)))
#ifdef __rtk__
#define CC_ASSERT(exp) ASSERT (exp)