From e93ec0bdce8286fb6b448fc26d43621eeffe8273 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20=C5=A0=C3=A1cha?= <[EMAIL REDACTED]>
Date: Thu, 17 Sep 2026 11:22:39 +0200
Subject: [PATCH] pixels: truncate `SDL_SetPaletteColors` input array silently
---
include/SDL3/SDL_pixels.h | 3 +++
src/video/SDL_pixels.c | 5 +----
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/SDL3/SDL_pixels.h b/include/SDL3/SDL_pixels.h
index 8da15e860ae51..889ebdeb3073c 100644
--- a/include/SDL3/SDL_pixels.h
+++ b/include/SDL3/SDL_pixels.h
@@ -1254,6 +1254,9 @@ extern SDL_DECLSPEC const SDL_PixelFormatDetails * SDLCALL SDL_GetPixelFormatDet
/**
* Create a palette structure with the specified number of color entries.
*
+ * If `ncolors` is larger than the palette's size - `firstcolor`,
+ * it is truncated to the amount that will fit.
+ *
* The palette entries are initialized to white.
*
* \param ncolors represents the number of color entries in the color palette.
diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c
index f005733936ec6..b488c03fc2039 100644
--- a/src/video/SDL_pixels.c
+++ b/src/video/SDL_pixels.c
@@ -1206,15 +1206,12 @@ SDL_Palette *SDL_CreatePalette(int ncolors)
bool SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
{
- bool result = true;
-
// Verify the parameters
if (!palette) {
return false;
}
if (ncolors > (palette->ncolors - firstcolor)) {
ncolors = (palette->ncolors - firstcolor);
- result = false;
}
if (colors != (palette->colors + firstcolor)) {
@@ -1226,7 +1223,7 @@ bool SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int fir
palette->version = 1;
}
- return result;
+ return true;
}
void SDL_DestroyPalette(SDL_Palette *palette)