Fixed memory corruption with invalid pixel values.
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Mar 2011 23:56:23 -0800
changeset 543629977c050731
parent 5435 3de226f0cc06
child 5437 ce10653e370c
Fixed memory corruption with invalid pixel values.
src/video/SDL_pixels.c
     1.1 --- a/src/video/SDL_pixels.c	Sun Mar 06 23:54:50 2011 -0800
     1.2 +++ b/src/video/SDL_pixels.c	Sun Mar 06 23:56:23 2011 -0800
     1.3 @@ -768,9 +768,13 @@
     1.4          v = (pixel & format->Bmask) >> format->Bshift;
     1.5          *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
     1.6      } else {
     1.7 -        *r = format->palette->colors[pixel].r;
     1.8 -        *g = format->palette->colors[pixel].g;
     1.9 -        *b = format->palette->colors[pixel].b;
    1.10 +        if (pixel < format->palette->ncolors) {
    1.11 +            *r = format->palette->colors[pixel].r;
    1.12 +            *g = format->palette->colors[pixel].g;
    1.13 +            *b = format->palette->colors[pixel].b;
    1.14 +        } else {
    1.15 +            *r = *g = *b = 0;
    1.16 +        }
    1.17      }
    1.18  }
    1.19  
    1.20 @@ -802,10 +806,14 @@
    1.21              *a = SDL_ALPHA_OPAQUE;
    1.22          }
    1.23      } else {
    1.24 -        *r = format->palette->colors[pixel].r;
    1.25 -        *g = format->palette->colors[pixel].g;
    1.26 -        *b = format->palette->colors[pixel].b;
    1.27 -        *a = SDL_ALPHA_OPAQUE;
    1.28 +        if (pixel < format->palette->ncolors) {
    1.29 +            *r = format->palette->colors[pixel].r;
    1.30 +            *g = format->palette->colors[pixel].g;
    1.31 +            *b = format->palette->colors[pixel].b;
    1.32 +            *a = SDL_ALPHA_OPAQUE;
    1.33 +        } else {
    1.34 +            *r = *g = *b = *a = 0;
    1.35 +        }
    1.36      }
    1.37  }
    1.38