Commit 2d5640cc authored by Sam Lantinga's avatar Sam Lantinga

Fixed memory corruption with invalid pixel values.

parent b2ad2a40
...@@ -768,9 +768,13 @@ SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g, ...@@ -768,9 +768,13 @@ SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g,
v = (pixel & format->Bmask) >> format->Bshift; v = (pixel & format->Bmask) >> format->Bshift;
*b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
} else { } else {
*r = format->palette->colors[pixel].r; if (pixel < format->palette->ncolors) {
*g = format->palette->colors[pixel].g; *r = format->palette->colors[pixel].r;
*b = format->palette->colors[pixel].b; *g = format->palette->colors[pixel].g;
*b = format->palette->colors[pixel].b;
} else {
*r = *g = *b = 0;
}
} }
} }
...@@ -802,10 +806,14 @@ SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, ...@@ -802,10 +806,14 @@ SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
*a = SDL_ALPHA_OPAQUE; *a = SDL_ALPHA_OPAQUE;
} }
} else { } else {
*r = format->palette->colors[pixel].r; if (pixel < format->palette->ncolors) {
*g = format->palette->colors[pixel].g; *r = format->palette->colors[pixel].r;
*b = format->palette->colors[pixel].b; *g = format->palette->colors[pixel].g;
*a = SDL_ALPHA_OPAQUE; *b = format->palette->colors[pixel].b;
*a = SDL_ALPHA_OPAQUE;
} else {
*r = *g = *b = *a = 0;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment