Fixed two inconsistencies on failed allocation.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 08 Feb 2015 22:50:16 +0100
changeset 9336 1a1ec75b608c
parent 9335 3eb0896ecb91
child 9337 7e5940a2cda6
Fixed two inconsistencies on failed allocation.
src/render/opengl/SDL_render_gl.c
src/video/SDL_bmp.c
--- a/src/render/opengl/SDL_render_gl.c	Sun Feb 08 15:44:15 2015 -0500
+++ b/src/render/opengl/SDL_render_gl.c	Sun Feb 08 22:50:16 2015 +0100
@@ -342,9 +342,10 @@
 
     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);
         }
--- a/src/video/SDL_bmp.c	Sun Feb 08 15:44:15 2015 -0500
+++ b/src/video/SDL_bmp.c	Sun Feb 08 22:50:16 2015 +0100
@@ -307,16 +307,17 @@
         }
         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;