SDL: Fixed unaligned 16-bit memory access

From e21f7d77f3ac73ac9dcc35c4ddcf3e7341cbd695 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 2 Apr 2026 14:08:20 -0700
Subject: [PATCH] Fixed unaligned 16-bit memory access

The previous code technically works on platforms with SSE2, but this fixes an ubsan warning.
---
 src/video/SDL_yuv.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c
index 3d09e97edc5f1..6b57d54dc10aa 100644
--- a/src/video/SDL_yuv.c
+++ b/src/video/SDL_yuv.c
@@ -1499,8 +1499,17 @@ static bool SDL_TARGETING("sse2") SDL_ConvertPixels_SwapNV_SSE2(int width, int h
             dstUV += 8;
             x -= 8;
         }
-        while (x--) {
-            *dstUV++ = SDL_Swap16(*srcUV++);
+        if (x > 0) {
+            const Uint8 *srcUV8 = (const Uint8 *)srcUV;
+            Uint8 *dstUV8 = (Uint8 *)dstUV;
+            srcUV += x;
+            dstUV += x;
+            while (x--) {
+                Uint8 u = *srcUV8++;
+                Uint8 v = *srcUV8++;
+                *dstUV8++ = v;
+                *dstUV8++ = u;
+            }
         }
         srcUV += srcUVPitchLeft;
         dstUV += dstUVPitchLeft;