Fail blits between indexed and RGB surfaces if there is no palette set

This commit is contained in:
Sam Lantinga 2024-07-16 11:58:31 -07:00
parent 9ca1792848
commit 626bb53772

View File

@ -1379,17 +1379,17 @@ static Uint8 *Map1toN(const SDL_Palette *pal, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod
int i;
int bpp;
if (!pal) {
SDL_SetError("src does not have a palette set");
return NULL;
}
bpp = ((SDL_BYTESPERPIXEL(dst->format) == 3) ? 4 : SDL_BYTESPERPIXEL(dst->format));
map = (Uint8 *)SDL_calloc(256, bpp);
if (!map) {
return NULL;
}
/* An all-zero map for surfaces without a palette. */
if (!pal) {
return map;
}
/* We memory copy to the pixel map so the endianness is preserved */
for (i = 0; i < pal->ncolors; ++i) {
Uint8 R = (Uint8)((pal->colors[i].r * Rmod) / 255);
@ -1410,7 +1410,7 @@ static Uint8 *MapNto1(const SDL_PixelFormatDetails *src, const SDL_Palette *pal,
SDL_Color colors[256];
if (!pal) {
*identical = 1;
SDL_SetError("dst does not have a palette set");
return NULL;
}