From 5a7a1eae35783b287fe0c9747b6f2cf59c7110a1 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 13 Jun 2026 08:33:24 +0300
Subject: [PATCH] tweak SDL2Compat_strlen() / volatile hack to be c++-23
compatible.
Reference issue: https://github.com/libsdl-org/sdl2-compat/issues/340.
---
src/sdl2_compat.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index c1cc5bcc..550672c9 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -272,11 +272,11 @@ SDL2COMPAT_itoa(char *dst, int val)
/* you can use SDL3_strlen once we're past startup. */
static int SDL2Compat_strlen(const char *str)
{
- volatile int retval = 0; /* volatile prevents gcc from optimizing this into strlen() */
- while (str[retval]) {
- retval++;
+ volatile const char *ptr = str;
+ while (*ptr) {
+ ++ptr;
}
- return retval;
+ return (int)(ptr - str);
}
/* you can use SDL3_strcmp once we're past startup. */