From 915f1b4b3d14d2acd6d5d29d75a1f0df1fca59a1 Mon Sep 17 00:00:00 2001
From: Michael Martin <[EMAIL REDACTED]>
Date: Fri, 21 Aug 2026 18:05:22 -0700
Subject: [PATCH] More faithfully track SDL_GetColorKey semantics
SDL3_GetSurfaceColorKey starts by writing 0 to *key if non-NULL.
SDL_GetColorKey only does so if the call will ultimately succeed.
This patch leaves the value of *key untouched on failure paths.
---
src/sdl2_compat.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index c8d0eec6..94f0c44f 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -10369,7 +10369,14 @@ SDL_HasColorKey(SDL2_Surface *surface)
SDL_DECLSPEC int SDLCALL
SDL_GetColorKey(SDL2_Surface *surface, Uint32 *key)
{
- return SDL3_GetSurfaceColorKey(Surface2to3(surface), key) ? 0 : -1;
+ Uint32 local_key;
+ if (SDL3_GetSurfaceColorKey(Surface2to3(surface), &local_key)) {
+ if (key) {
+ *key = local_key;
+ }
+ return 0;
+ }
+ return -1;
}
SDL_DECLSPEC int SDLCALL