summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2008-12-07 22:25:16 +0000
committerSam Lantinga <slouken@libsdl.org>2008-12-07 22:25:16 +0000
commit7e9c50dc267240a71b4ed8559f1a0dea2094bdef (patch)
treea50c81d9f15a289ece9adbbd2a7ab41f520a9d7d /src
parentf29cdbb9b7ab3922472f4baadec11fac0fe8bfee (diff)
Fixed crash in testpalette and potential crash in SDL_LoadBMP_RW()
Diffstat (limited to 'src')
-rw-r--r--src/video/SDL_bmp.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index 2ddf8f85b7..66c5018cb9 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -218,6 +218,20 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
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);