Просмотр исходного кода

pixels: truncate `SDL_SetPaletteColors` input array silently

Petr Šácha 4 дней назад
Родитель
Сommit
e93ec0bdce
2 измененных файлов с 4 добавлено и 4 удалено
  1. 3 0
      include/SDL3/SDL_pixels.h
  2. 1 4
      src/video/SDL_pixels.c

+ 3 - 0
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.
  * 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.
  * The palette entries are initialized to white.
  *
  *
  * \param ncolors represents the number of color entries in the color palette.
  * \param ncolors represents the number of color entries in the color palette.

+ 1 - 4
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 SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
 {
 {
-    bool result = true;
-
     // Verify the parameters
     // Verify the parameters
     if (!palette) {
     if (!palette) {
         return false;
         return false;
     }
     }
     if (ncolors > (palette->ncolors - firstcolor)) {
     if (ncolors > (palette->ncolors - firstcolor)) {
         ncolors = (palette->ncolors - firstcolor);
         ncolors = (palette->ncolors - firstcolor);
-        result = false;
     }
     }
 
 
     if (colors != (palette->colors + firstcolor)) {
     if (colors != (palette->colors + firstcolor)) {
@@ -1226,7 +1223,7 @@ bool SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int fir
         palette->version = 1;
         palette->version = 1;
     }
     }
 
 
-    return result;
+    return true;
 }
 }
 
 
 void SDL_DestroyPalette(SDL_Palette *palette)
 void SDL_DestroyPalette(SDL_Palette *palette)