sdl12-compat: SDL2Compat_strlen: hack to prevent gcc optimizing the code into strlen

From 283ecc78aa78cef409ba2a189feafe86e884496a Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Mon, 10 Feb 2025 23:37:40 +0300
Subject: [PATCH] SDL2Compat_strlen: hack to prevent gcc optimizing the code
 into strlen

making retval volatile prevents gcc optimizing the code into strlen and
defeating the purpose of the procedure.

Reference issue:  https://github.com/libsdl-org/sdl2-compat/issues/340
---
 src/SDL12_compat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 9f16a96af..78936dd91 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -1145,7 +1145,7 @@ SDL12COMPAT_itoa(char *dst, int val)
 /* you can use SDL20_strlen once we're past startup. */
 static int SDL12COMPAT_strlen(const char *str)
 {
-    int retval = 0;
+    volatile int retval = 0;  /* volatile prevents gcc from optimizing this into strlen() */
     while (str[retval]) {
         retval++;
     }