mirror of
https://github.com/blawar/GLideN64.git
synced 2024-06-30 08:24:05 +00:00
fixed heap overflow
This commit is contained in:
parent
a054cb622b
commit
35b278896f
|
@ -103,7 +103,45 @@ const volatile unsigned char One2Eight[2] =
|
||||||
void UnswapCopyWrap(const u8 *src, word srcIdx, u8 *dest, word destIdx, word destMask, word numBytes)
|
void UnswapCopyWrap(const u8 *src, word srcIdx, u8 *dest, word destIdx, word destMask, word numBytes)
|
||||||
{
|
{
|
||||||
#ifdef NATIVE
|
#ifdef NATIVE
|
||||||
memcpy(dest + destIdx, src + srcIdx, numBytes);
|
// copy leading bytes
|
||||||
|
word leadingBytes = srcIdx & 3;
|
||||||
|
if(leadingBytes != 0)
|
||||||
|
{
|
||||||
|
leadingBytes = 4 - leadingBytes;
|
||||||
|
if(leadingBytes > numBytes)
|
||||||
|
leadingBytes = numBytes;
|
||||||
|
numBytes -= leadingBytes;
|
||||||
|
|
||||||
|
for(u32 i = 0; i < leadingBytes; i++)
|
||||||
|
{
|
||||||
|
dest[destIdx & destMask] = src[srcIdx];
|
||||||
|
++destIdx;
|
||||||
|
++srcIdx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy dwords
|
||||||
|
int numDWords = numBytes >> 2;
|
||||||
|
while(numDWords--)
|
||||||
|
{
|
||||||
|
dest[(destIdx + 0) & destMask] = src[srcIdx++];
|
||||||
|
dest[(destIdx + 1) & destMask] = src[srcIdx++];
|
||||||
|
dest[(destIdx + 2) & destMask] = src[srcIdx++];
|
||||||
|
dest[(destIdx + 3) & destMask] = src[srcIdx++];
|
||||||
|
destIdx += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy trailing bytes
|
||||||
|
int trailingBytes = numBytes & 3;
|
||||||
|
if(trailingBytes)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < trailingBytes; i++)
|
||||||
|
{
|
||||||
|
dest[destIdx & destMask] = src[srcIdx];
|
||||||
|
++destIdx;
|
||||||
|
++srcIdx;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
// copy leading bytes
|
// copy leading bytes
|
||||||
word leadingBytes = srcIdx & 3;
|
word leadingBytes = srcIdx & 3;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user