From ac2da24150a969860de50ec819776cabe7e8df2a Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Mon, 15 Jun 2026 12:20:34 +0100
Subject: [PATCH] Restore comment explaining why volatile is used in
SDL2Compat_strlen()
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
src/sdl2_compat.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 550672c9..8f0db91a 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -272,6 +272,9 @@ SDL2COMPAT_itoa(char *dst, int val)
/* you can use SDL3_strlen once we're past startup. */
static int SDL2Compat_strlen(const char *str)
{
+ /* volatile prevents gcc from optimizing this into a call to the
+ * strlen() library function, which we are intentionally avoiding on
+ * Windows: see #340 */
volatile const char *ptr = str;
while (*ptr) {
++ptr;