sw_raster c: fix the misaligned memory access.

An issue occurred in the 64-bit accelerated raster version,
involving 8 bytes of misaligned memory access.

This was detected by the memory sanitizer and has now been fixed.
This commit is contained in:
Hermet Park 2023-07-29 00:45:37 +09:00 committed by Hermet Park
parent f551531bb5
commit 24c0b5ecf5

View file

@ -26,18 +26,16 @@ static void inline cRasterPixels(PIXEL_T* dst, PIXEL_T val, uint32_t offset, int
dst += offset;
//fix the misaligned memory
auto alignOffset = 0;
if (sizeof(PIXEL_T) == 4) alignOffset = offset % 2;
else if (sizeof(PIXEL_T) == 1) {
alignOffset = offset % 8;
if (alignOffset > 0) alignOffset = 8 - alignOffset;
}
auto alignOffset = (long) dst % 8;
if (alignOffset > 0) {
if (sizeof(PIXEL_T) == 4) alignOffset /= 4;
else if (sizeof(PIXEL_T) == 1) alignOffset = 8 - alignOffset;
while (alignOffset > 0 && len > 0) {
*dst++ = val;
--len;
--alignOffset;
}
}
//64bits faster clear
if ((sizeof(PIXEL_T) == 4)) {