Handle address-of-packed-member warning

Where possible make pointers uint8_t *

For uint16_t data, use uint8_t * pointer and
copy data with memcpy.
fix/address_of_packed_member
Andreas Karlsson 2022-11-10 21:05:51 +01:00
parent a7a017c26f
commit 426285abd4
1 changed files with 21 additions and 19 deletions

View File

@ -41,6 +41,13 @@
typedef enum { UPLOAD, DOWNLOAD } load_t; typedef enum { UPLOAD, DOWNLOAD } load_t;
/* may be used on packed uint32_t members */
CC_STATIC_ASSERT((sizeof(_COEsdo) % 4) == 0);
CC_STATIC_ASSERT((offsetof(_COEsdo, size) % 4) == 0);
/* may be used on packed uint16_t members */
CC_STATIC_ASSERT((offsetof(_COEobjdesc, datatype) % 2) == 0);
CC_STATIC_ASSERT((offsetof(_COEobjdesc, maxsub) % 2) == 0);
/** Search for an object sub-index. /** Search for an object sub-index.
* *
* @param[in] nidx = local array index of object we want to find sub-index to * @param[in] nidx = local array index of object we want to find sub-index to
@ -756,7 +763,7 @@ static void SDO_download (void)
uint8_t MBXout; uint8_t MBXout;
uint16_t size, actsize; uint16_t size, actsize;
const _objd *objd; const _objd *objd;
uint32_t *mbxdata; uint8_t *mbxdata;
uint32_t abort; uint32_t abort;
coesdo = (_COEsdo *) &MBX[0]; coesdo = (_COEsdo *) &MBX[0];
@ -777,13 +784,13 @@ static void SDO_download (void)
if (coesdo->command & COE_EXPEDITED_INDICATOR) if (coesdo->command & COE_EXPEDITED_INDICATOR)
{ {
size = 4 - ((coesdo->command & 0x0c) >> 2); size = 4 - ((coesdo->command & 0x0c) >> 2);
mbxdata = &(coesdo->size); mbxdata = &MBX[offsetof(_COEsdo, size)];
} }
else else
{ {
/* normal download */ /* normal download */
size = (etohl (coesdo->size) & 0xffff); size = (etohl (coesdo->size) & 0xffff);
mbxdata = (&(coesdo->size)) + 1; mbxdata = &MBX[sizeof(_COEsdo)];
} }
actsize = BITS2BYTES((objd + nsub)->bitlength); actsize = BITS2BYTES((objd + nsub)->bitlength);
if (actsize != size) if (actsize != size)
@ -907,18 +914,19 @@ static void SDO_download_complete_access (void)
} }
uint32_t bytes; uint32_t bytes;
uint32_t *mbxdata = &(coesdo->size); uint8_t *mbxdata;
if (coesdo->command & COE_EXPEDITED_INDICATOR) if (coesdo->command & COE_EXPEDITED_INDICATOR)
{ {
/* expedited download */ /* expedited download */
bytes = 4 - ((coesdo->command & 0x0c) >> 2); bytes = 4 - ((coesdo->command & 0x0c) >> 2);
mbxdata = &MBX[offsetof(_COEsdo, size)];
} }
else else
{ {
/* normal download */ /* normal download */
bytes = (etohl (coesdo->size) & 0xffff); bytes = (etohl (coesdo->size) & 0xffff);
mbxdata++; mbxdata = &MBX[sizeof(_COEsdo)];
} }
const _objd *objd = SDOobjects[nidx].objdesc; const _objd *objd = SDOobjects[nidx].objdesc;
@ -1123,7 +1131,7 @@ static void SDO_getodlist (void)
uint8_t MBXout = 0; uint8_t MBXout = 0;
uint16_t entries = 0; uint16_t entries = 0;
uint16_t i, n; uint16_t i, n;
uint16_t *p; uint8_t *p;
_COEobjdesc *coel, *coer; _COEobjdesc *coel, *coer;
while (SDOobjects[entries].index != 0xffff) while (SDOobjects[entries].index != 0xffff)
@ -1161,16 +1169,9 @@ static void SDO_getodlist (void)
ESCvar.xoe = 0; ESCvar.xoe = 0;
ESCvar.frags = frags; ESCvar.frags = frags;
ESCvar.fragsleft = frags - 1; ESCvar.fragsleft = frags - 1;
p = &(coel->datatype); coel->datatype = htoes (entries);
*p = htoes (entries); p = &MBX[MBXout * ESC_MBXSIZE + offsetof(_COEobjdesc, maxsub)];
p++; memset(p, 0, sizeof(uint16_t) * 4);
*p = 0;
p++;
*p = 0;
p++;
*p = 0;
p++;
*p = 0;
coel->mbxheader.length = htoes (0x08 + (5 << 1)); coel->mbxheader.length = htoes (0x08 + (5 << 1));
} }
/* only return all objects */ /* only return all objects */
@ -1195,11 +1196,12 @@ static void SDO_getodlist (void)
coel->infoheader.fragmentsleft = htoes (ESCvar.fragsleft); coel->infoheader.fragmentsleft = htoes (ESCvar.fragsleft);
coel->index = htoes ((uint16_t) 0x01); coel->index = htoes ((uint16_t) 0x01);
p = &(coel->datatype); p = &MBX[MBXout * ESC_MBXSIZE + offsetof(_COEobjdesc, datatype)];
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
*p = htoes (SDOobjects[i].index); uint16_t p_value = htoes (SDOobjects[i].index);
p++; memcpy(p, &p_value, sizeof(p_value));
p += 2;
} }
coel->mbxheader.length = htoes (0x08 + (n << 1)); coel->mbxheader.length = htoes (0x08 + (n << 1));