@@ -416,7 +416,9 @@ static SDL_INLINE void BG_Blended_Color(const TTF_Image *image, Uint32 *destinat
416416 while (height -- ) {
417417 /* *INDENT-OFF* */
418418 DUFFS_LOOP4 (
419- tmp = * src ++ ;
419+ /* prevent misaligned load: tmp = *src++; */
420+ /* eventually, we can expect the compiler to replace the memcpy call with something optimized */
421+ memcpy (& tmp , src ++ , sizeof (tmp )); /* This should NOT be SDL_memcpy */
420422 alpha = tmp >> 24 ;
421423 tmp &= ~0xFF000000 ;
422424 alpha = fg_alpha * alpha ;
@@ -451,7 +453,8 @@ static SDL_INLINE void BG_Blended_LCD(const TTF_Image *image, Uint32 *destinatio
451453 while (height -- ) {
452454 /* *INDENT-OFF* */
453455 DUFFS_LOOP4 (
454- tmp = * src ++ ;
456+ /* prevent misaligned load: tmp = *src++; */
457+ memcpy (& tmp , src ++ , sizeof (tmp )); /* This should NOT be SDL_memcpy */
455458
456459 if (tmp ) {
457460 bg = * dst ;
@@ -908,11 +911,14 @@ static SDL_INLINE void BG_64(const TTF_Image *image, Uint8 *destination, Sint32
908911 Uint64 * dst = (Uint64 * )destination ;
909912 Uint32 width = image -> width / 8 ;
910913 Uint32 height = image -> rows ;
914+ Uint64 tmp ;
911915
912916 while (height -- ) {
913917 /* *INDENT-OFF* */
914918 DUFFS_LOOP4 (
915- * dst ++ |= * src ++ ;
919+ /* prevent misaligned load: *dst++ |= *src++; */
920+ memcpy (& tmp , src ++ , sizeof (tmp )); /* This should NOT be SDL_memcpy */
921+ * dst ++ |= tmp ;
916922 , width );
917923 /* *INDENT-ON* */
918924 src = (const Uint64 * )((const Uint8 * )src + srcskip );
@@ -926,11 +932,14 @@ static SDL_INLINE void BG_32(const TTF_Image *image, Uint8 *destination, Sint32
926932 Uint32 * dst = (Uint32 * )destination ;
927933 Uint32 width = image -> width / 4 ;
928934 Uint32 height = image -> rows ;
935+ Uint32 tmp ;
929936
930937 while (height -- ) {
931938 /* *INDENT-OFF* */
932939 DUFFS_LOOP4 (
933- * dst ++ |= * src ++ ;
940+ /* prevent misaligned load: *dst++ |= *src++; */
941+ memcpy (& tmp , src ++ , sizeof (tmp )); /* This should NOT be SDL_memcpy */
942+ * dst ++ |= tmp ;
934943 , width );
935944 /* *INDENT-ON* */
936945 src = (const Uint32 * )((const Uint8 * )src + srcskip );
0 commit comments