Skip to content

Commit

Permalink
stm32/st_usbfs_v2: Fixed the use of pointer maths on void pointers in…
Browse files Browse the repository at this point in the history
… the packet I/O code
  • Loading branch information
dragonmux committed Jan 14, 2024
1 parent 1b44842 commit 5429f1a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/stm32/st_usbfs_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,22 @@ void st_usbfs_copy_from_pm(void *buf, const volatile void *vPM, uint16_t len)
uint8_t odd = len & 1;
len >>= 1;

if (((uintptr_t) buf) & 0x01) {
if (((uintptr_t)buf) & 0x01) {
uint8_t *dest = (uint8_t *)buf;
for (; len; PM++, len--) {
uint16_t value = *PM;
*(uint8_t *) buf++ = value;
*(uint8_t *) buf++ = value >> 8;
*(uint8_t *)dest++ = value;
*(uint8_t *)dest++ = value >> 8;
}
} else {
for (; len; PM++, buf += 2, len--) {
*(uint16_t *) buf = *PM;
uint16_t *dest = (uint16_t *)buf;
for (; len; PM++, dest++, len--) {
*dest = *PM;
}
}

if (odd) {
*(uint8_t *) buf = *(uint8_t *) PM;
*(uint8_t *)buf = *(uint8_t *)PM;
}
}

Expand Down

0 comments on commit 5429f1a

Please sign in to comment.