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;