diff 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
line wrap: on
line diff
--- a/src/video/SDL_bmp.c	Sun Dec 07 22:04:24 2008 +0000
+++ b/src/video/SDL_bmp.c	Sun Dec 07 22:25:16 2008 +0000
@@ -218,6 +218,20 @@
         if (biClrUsed == 0) {
             biClrUsed = 1 << biBitCount;
         }
+        if (biClrUsed > palette->ncolors) {
+            palette->ncolors = biClrUsed;
+            palette->colors =
+                (SDL_Color *) SDL_realloc(palette->colors,
+                                          palette->ncolors *
+                                          sizeof(*palette->colors));
+            if (!palette->colors) {
+                SDL_OutOfMemory();
+                was_error = 1;
+                goto done;
+            }
+        } else if (biClrUsed < palette->ncolors) {
+            palette->ncolors = biClrUsed;
+        }
         if (biSize == 12) {
             for (i = 0; i < (int) biClrUsed; ++i) {
                 SDL_RWread(src, &palette->colors[i].b, 1, 1);