From ba170daf84d3528c4f96ea453bb660be4b184a36 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 27 Jun 2023 16:07:56 -0700 Subject: [PATCH] Don't crash if SDL_MapRGB() and SDL_MapRGBA() are passed a NULL format (cherry picked from commit fadc4916a9bcc410c2148a91bf0adf742410a4ba) (cherry picked from commit 0ba93e4aac8232de45e2a6df4d0a42ec53f53ec3) --- src/video/SDL_pixels.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 81892e7a0e..65e33ab861 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -852,6 +852,10 @@ void SDL_DetectPalette(SDL_Palette *pal, SDL_bool *is_opaque, SDL_bool *has_alph /* Find the opaque pixel value corresponding to an RGB triple */ Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b) { + if (!format) { + SDL_InvalidParamError("format"); + return 0; + } if (format->palette == NULL) { return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask; } else { @@ -862,6 +866,10 @@ Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b) /* Find the pixel value corresponding to an RGBA quadruple */ Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { + if (!format) { + SDL_InvalidParamError("format"); + return 0; + } if (format->palette == NULL) { return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | ((Uint32)(a >> format->Aloss) << format->Ashift & format->Amask); } else {