Skip to content

Commit

Permalink
Merge pull request #661 from bigtreetech/master
Browse files Browse the repository at this point in the history
[bugfix] Restore overflowed memory copy
  • Loading branch information
stevstrong authored Sep 14, 2019
2 parents 1b6baa5 + 1264166 commit b14d08c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions STM32F1/cores/maple/libmaple/usb/usb_lib/usb_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ void UserToPMABufferCopy(const u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
*******************************************************************************/
void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
{
u32 n = (wNBytes + 1) >> 1;/* /2*/
u32 i;
u32 *pdwVal;
pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr);
for (i = n; i != 0; i--)
u16 * destPtr = (u16*)pbUsrBuf;
u32 * pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr);
for (u16 i = wNBytes/2; i > 0; i--)
{
*(u16*)pbUsrBuf++ = *pdwVal++;
pbUsrBuf++;
*destPtr++ = (u16)*pdwVal++;
}
if (wNBytes & 0x1) // odd value ?
{
*(u8*)destPtr = *(u8*)pdwVal;
}
}

Expand Down

0 comments on commit b14d08c

Please sign in to comment.