From e3f9bf3378c45148c35c62a814d9817c8ca2e953 Mon Sep 17 00:00:00 2001 From: Philipp Wiesemann Date: Sun, 8 Feb 2015 22:50:16 +0100 Subject: [PATCH] Fixed two inconsistencies on failed allocation. --- src/render/opengl/SDL_render_gl.c | 5 +++-- src/video/SDL_bmp.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index f34bf1288..0c930f35d 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -342,9 +342,10 @@ GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GL if (type == GL_DEBUG_TYPE_ERROR_ARB) { /* Record this error */ - char **error_messages = SDL_realloc(data->error_messages, data->errors * sizeof(*data->error_messages)); - ++data->errors; + int errors = data->errors + 1; + char **error_messages = SDL_realloc(data->error_messages, errors * sizeof(*data->error_messages)); if (error_messages) { + data->errors = errors; data->error_messages = error_messages; data->error_messages[data->errors-1] = SDL_strdup(message); } diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index c5de8f00f..f2b19fabd 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -307,16 +307,17 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc) } if ((int) biClrUsed > palette->ncolors) { SDL_Color *colors; - palette->ncolors = biClrUsed; + int ncolors = biClrUsed; colors = (SDL_Color *) SDL_realloc(palette->colors, - palette->ncolors * + ncolors * sizeof(*palette->colors)); if (!colors) { SDL_OutOfMemory(); was_error = SDL_TRUE; goto done; } + palette->ncolors = ncolors; palette->colors = colors; } else if ((int) biClrUsed < palette->ncolors) { palette->ncolors = biClrUsed;