瀏覽代碼

Don't crash if SDL_MapRGB() and SDL_MapRGBA() are passed a NULL format

Sam Lantinga 3 年之前
父節點
當前提交
cc5e9ffe70
共有 1 個文件被更改,包括 8 次插入 和 0 次删除
  1. 8 0
      src/video/SDL_pixels.c

+ 8 - 0
src/video/SDL_pixels.c

@@ -857,6 +857,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 */
 /* Find the opaque pixel value corresponding to an RGB triple */
 Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
 Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
 {
 {
+    if (!format) {
+        SDL_InvalidParamError("format");
+        return 0;
+    }
     if (format->palette == NULL) {
     if (format->palette == NULL) {
         return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
         return (r >> format->Rloss) << format->Rshift | (g >> format->Gloss) << format->Gshift | (b >> format->Bloss) << format->Bshift | format->Amask;
     } else {
     } else {
@@ -868,6 +872,10 @@ Uint32 SDL_MapRGB(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b)
 Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b,
 Uint32 SDL_MapRGBA(const SDL_PixelFormat *format, Uint8 r, Uint8 g, Uint8 b,
             Uint8 a)
             Uint8 a)
 {
 {
+    if (!format) {
+        SDL_InvalidParamError("format");
+        return 0;
+    }
     if (format->palette == NULL) {
     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);
         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 {
     } else {