use copy loops instead of memcpy/memmove

because different versions of gcc seem to disagree on how both of these
functions should handle overlapping memory. thanks stallman
This commit is contained in:
devinacker 2013-10-26 14:41:21 -04:00
parent e8fb851b50
commit f8ed01c458

View file

@ -158,6 +158,8 @@ size_t unpack(uint8_t *packed, uint8_t *unpacked) {
switch (command) {
// write uncompressed bytes
// (note: i had to go back to using loops for all of these because memcpy/memmove
// were both fucking up and handling these inconsistently between versions of gcc)
case 0:
memcpy(&unpacked[outpos], &packed[inpos], length);
@ -167,19 +169,19 @@ size_t unpack(uint8_t *packed, uint8_t *unpacked) {
// 8-bit RLE
case 1:
unpacked[outpos] = packed[inpos++];
memcpy(&unpacked[outpos + 1], &unpacked[outpos], length - 1);
for (int i = 0; i < length; i++)
unpacked[outpos++] = packed[inpos];
outpos += length;
inpos++;
break;
// 16-bit RLE
case 2:
unpacked[outpos] = packed[inpos];
unpacked[outpos + 1] = packed[inpos + 1];
memcpy(&unpacked[outpos + 2], &unpacked[outpos], 2 * (length - 1));
for (int i = 0; i < length; i++) {
unpacked[outpos++] = packed[inpos];
unpacked[outpos++] = packed[inpos+1];
}
outpos += (length * 2);
inpos += 2;
break;
@ -201,9 +203,9 @@ size_t unpack(uint8_t *packed, uint8_t *unpacked) {
command = 4;
offset = (packed[inpos] << 8) | packed[inpos+1];
memcpy(&unpacked[outpos], &unpacked[offset], length);
for (int i = 0; i < length; i++)
unpacked[outpos++] = unpacked[offset + i];
outpos += length;
inpos += 2;
break;