Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug #324 - prevent unaligned load access #329

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/SDL_ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ static SDL_INLINE void BG_Blended_Color(const TTF_Image *image, Uint32 *destinat
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP4(
tmp = *src++;
/* prevent misaligned load: tmp = *src++; */
/* eventually, we can expect the compiler to replace the memcpy call with something optimized */
memcpy(&tmp, src++, sizeof(tmp)); /* This should NOT be SDL_memcpy */
alpha = tmp >> 24;
tmp &= ~0xFF000000;
alpha = fg_alpha * alpha;
Expand Down Expand Up @@ -426,7 +428,8 @@ static SDL_INLINE void BG_Blended_LCD(const TTF_Image *image, Uint32 *destinatio
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP4(
tmp = *src++;
/* prevent misaligned load: tmp = *src++; */
memcpy(&tmp, src++, sizeof(tmp)); /* This should NOT be SDL_memcpy */

if (tmp) {
bg = *dst;
Expand Down Expand Up @@ -883,11 +886,14 @@ static SDL_INLINE void BG_64(const TTF_Image *image, Uint8 *destination, Sint32
Uint64 *dst = (Uint64 *)destination;
Uint32 width = image->width / 8;
Uint32 height = image->rows;
Uint64 tmp;

while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP4(
*dst++ |= *src++;
/* prevent misaligned load: *dst++ |= *src++; */
memcpy(&tmp, src++, sizeof(tmp)); /* This should NOT be SDL_memcpy */
*dst++ |= tmp;
, width);
/* *INDENT-ON* */
src = (const Uint64 *)((const Uint8 *)src + srcskip);
Expand All @@ -901,11 +907,14 @@ static SDL_INLINE void BG_32(const TTF_Image *image, Uint8 *destination, Sint32
Uint32 *dst = (Uint32 *)destination;
Uint32 width = image->width / 4;
Uint32 height = image->rows;
Uint32 tmp;

while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP4(
*dst++ |= *src++;
/* prevent misaligned load: *dst++ |= *src++; */
memcpy(&tmp, src++, sizeof(tmp)); /* This should NOT be SDL_memcpy */
*dst++ |= tmp;
, width);
/* *INDENT-ON* */
src = (const Uint32 *)((const Uint8 *)src + srcskip);
Expand Down
Loading