comparison src/video/SDL_bmp.c @ 2851:6c3fbeb04eca

Fixed crash in testpalette and potential crash in SDL_LoadBMP_RW()
author Sam Lantinga <slouken@libsdl.org>
date Sun, 07 Dec 2008 22:25:16 +0000
parents 15e1dd1fff78
children 99210400e8b9
comparison
equal deleted inserted replaced
2850:43691ef70176 2851:6c3fbeb04eca
216 palette = (surface->format)->palette; 216 palette = (surface->format)->palette;
217 if (palette) { 217 if (palette) {
218 if (biClrUsed == 0) { 218 if (biClrUsed == 0) {
219 biClrUsed = 1 << biBitCount; 219 biClrUsed = 1 << biBitCount;
220 } 220 }
221 if (biClrUsed > palette->ncolors) {
222 palette->ncolors = biClrUsed;
223 palette->colors =
224 (SDL_Color *) SDL_realloc(palette->colors,
225 palette->ncolors *
226 sizeof(*palette->colors));
227 if (!palette->colors) {
228 SDL_OutOfMemory();
229 was_error = 1;
230 goto done;
231 }
232 } else if (biClrUsed < palette->ncolors) {
233 palette->ncolors = biClrUsed;
234 }
221 if (biSize == 12) { 235 if (biSize == 12) {
222 for (i = 0; i < (int) biClrUsed; ++i) { 236 for (i = 0; i < (int) biClrUsed; ++i) {
223 SDL_RWread(src, &palette->colors[i].b, 1, 1); 237 SDL_RWread(src, &palette->colors[i].b, 1, 1);
224 SDL_RWread(src, &palette->colors[i].g, 1, 1); 238 SDL_RWread(src, &palette->colors[i].g, 1, 1);
225 SDL_RWread(src, &palette->colors[i].r, 1, 1); 239 SDL_RWread(src, &palette->colors[i].r, 1, 1);