Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)
authorSam Lantinga <slouken@libsdl.org>
Thu, 29 Aug 2013 08:29:51 -0700
changeset 7720 f9a649383362
parent 7719 31b5f9ff36ca
child 7721 bdf8c2c84e14
Christoph Mallon: Remove pointless if (x) before SDL_FreeSurface(x)
src/events/SDL_mouse.c
src/render/SDL_yuv_sw.c
src/video/SDL_bmp.c
src/video/SDL_video.c
src/video/directfb/SDL_DirectFB_window.c
src/video/dummy/SDL_nullframebuffer.c
test/testautomation_render.c
test/testautomation_surface.c
test/testshape.c
--- a/src/events/SDL_mouse.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/src/events/SDL_mouse.c	Thu Aug 29 08:29:51 2013 -0700
@@ -571,9 +571,7 @@
         mouse->cursors = cursor;
     }
 
-    if (temp) {
-        SDL_FreeSurface(temp);
-    }
+    SDL_FreeSurface(temp);
 
     return cursor;
 }
--- a/src/render/SDL_yuv_sw.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/src/render/SDL_yuv_sw.c	Thu Aug 29 08:29:51 2013 -0700
@@ -1012,10 +1012,8 @@
         break;
     }
 
-    if (swdata->display) {
-        SDL_FreeSurface(swdata->display);
-        swdata->display = NULL;
-    }
+    SDL_FreeSurface(swdata->display);
+    swdata->display = NULL;
     return 0;
 }
 
@@ -1338,12 +1336,8 @@
         SDL_free(swdata->pixels);
         SDL_free(swdata->colortab);
         SDL_free(swdata->rgb_2_pix);
-        if (swdata->stretch) {
-            SDL_FreeSurface(swdata->stretch);
-        }
-        if (swdata->display) {
-            SDL_FreeSurface(swdata->display);
-        }
+        SDL_FreeSurface(swdata->stretch);
+        SDL_FreeSurface(swdata->display);
         SDL_free(swdata);
     }
 }
--- a/src/video/SDL_bmp.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/src/video/SDL_bmp.c	Thu Aug 29 08:29:51 2013 -0700
@@ -398,9 +398,7 @@
         if (src) {
             SDL_RWseek(src, fp_offset, RW_SEEK_SET);
         }
-        if (surface) {
-            SDL_FreeSurface(surface);
-        }
+        SDL_FreeSurface(surface);
         surface = NULL;
     }
     if (freesrc && src) {
--- a/src/video/SDL_video.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/src/video/SDL_video.c	Thu Aug 29 08:29:51 2013 -0700
@@ -1432,9 +1432,7 @@
         return;
     }
 
-    if (window->icon) {
-        SDL_FreeSurface(window->icon);
-    }
+    SDL_FreeSurface(window->icon);
 
     /* Convert the icon into ARGB8888 */
     window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888, 0);
@@ -2183,9 +2181,7 @@
 
     /* Free memory associated with the window */
     SDL_free(window->title);
-    if (window->icon) {
-        SDL_FreeSurface(window->icon);
-    }
+    SDL_FreeSurface(window->icon);
     SDL_free(window->gamma);
     while (window->data) {
         SDL_WindowUserData *data = window->data;
--- a/src/video/directfb/SDL_DirectFB_window.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/src/video/directfb/SDL_DirectFB_window.c	Thu Aug 29 08:29:51 2013 -0700
@@ -237,8 +237,7 @@
     }
     return;
   error:
-    if (surface)
-        SDL_FreeSurface(surface);
+    SDL_FreeSurface(surface);
     SDL_DFB_RELEASE(windata->icon);
     return;
 }
--- a/src/video/dummy/SDL_nullframebuffer.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/src/video/dummy/SDL_nullframebuffer.c	Thu Aug 29 08:29:51 2013 -0700
@@ -38,9 +38,7 @@
 
     /* Free the old framebuffer surface */
     surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE);
-    if (surface) {
-        SDL_FreeSurface(surface);
-    }
+    SDL_FreeSurface(surface);
 
     /* Create a new one */
     SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
@@ -83,9 +81,7 @@
     SDL_Surface *surface;
 
     surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL);
-    if (surface) {
-        SDL_FreeSurface(surface);
-    }
+    SDL_FreeSurface(surface);
 }
 
 #endif /* SDL_VIDEO_DRIVER_DUMMY */
--- a/test/testautomation_render.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/test/testautomation_render.c	Thu Aug 29 08:29:51 2013 -0700
@@ -190,10 +190,8 @@
    _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
 
    /* Clean up. */
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    return TEST_COMPLETED;
 }
@@ -333,10 +331,8 @@
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
 
    /* Clean up. */
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    return TEST_COMPLETED;
 }
@@ -400,10 +396,8 @@
 
    /* Clean up. */
    SDL_DestroyTexture( tface );
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    return TEST_COMPLETED;
 }
@@ -470,10 +464,8 @@
 
    /* Clean up. */
    SDL_DestroyTexture( tface );
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    return TEST_COMPLETED;
 }
@@ -543,10 +535,8 @@
 
    /* Clean up. */
    SDL_DestroyTexture( tface );
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    return TEST_COMPLETED;
 }
@@ -655,37 +645,29 @@
    _testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
    referenceSurface = SDLTest_ImageBlitBlendNone();
    _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    /* Test Blend. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
    referenceSurface = SDLTest_ImageBlitBlend();
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    /* Test Add. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
    referenceSurface = SDLTest_ImageBlitBlendAdd();
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    /* Test Mod. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
    referenceSurface = SDLTest_ImageBlitBlendMod();
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    /* Clear surface. */
    _clearScreen();
@@ -733,10 +715,8 @@
    /* Check to see if final image matches. */
    referenceSurface = SDLTest_ImageBlitBlendAll();
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
-   if (referenceSurface != NULL) {
-      SDL_FreeSurface(referenceSurface);
-      referenceSurface = NULL;
-   }
+   SDL_FreeSurface(referenceSurface);
+   referenceSurface = NULL;
 
    return TEST_COMPLETED;
 }
@@ -996,9 +976,7 @@
 
    /* Clean up. */
    SDL_free(pixels);
-   if (testSurface != NULL) {
-       SDL_FreeSurface(testSurface);
-   }
+   SDL_FreeSurface(testSurface);
 }
 
 /**
--- a/test/testautomation_surface.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/test/testautomation_surface.c	Thu Aug 29 08:29:51 2013 -0700
@@ -63,14 +63,10 @@
 void
 _surfaceTearDown(void *arg)
 {
-    if (referenceSurface != NULL) {
-        SDL_FreeSurface(referenceSurface);
-        referenceSurface = NULL;
-    }
-    if (testSurface != NULL) {
-        SDL_FreeSurface(testSurface);
-        testSurface = NULL;
-    }
+    SDL_FreeSurface(referenceSurface);
+    referenceSurface = NULL;
+    SDL_FreeSurface(testSurface);
+    testSurface = NULL;
 }
 
 /**
@@ -193,10 +189,8 @@
     SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
 
     /* Clean up */
-    if (face != NULL) {
-        SDL_FreeSurface(face);
-        face = NULL;
-    }
+    SDL_FreeSurface(face);
+    face = NULL;
 }
 
 /* Helper to check that a file exists */
@@ -250,14 +244,10 @@
     unlink(sampleFilename);
 
     /* Clean up */
-    if (face != NULL) {
     SDL_FreeSurface(face);
     face = NULL;
-    }
-    if (rface != NULL) {
     SDL_FreeSurface(rface);
     rface = NULL;
-    }
 
     return TEST_COMPLETED;
 }
@@ -294,14 +284,10 @@
     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
     /* Clean up. */
-    if (face != NULL) {
-        SDL_FreeSurface( face );
-        face = NULL;
-    }
-    if (rface != NULL) {
-        SDL_FreeSurface( rface );
-        rface = NULL;
-    }
+    SDL_FreeSurface(face);
+    face = NULL;
+    SDL_FreeSurface(rface);
+    rface = NULL;
 
     return TEST_COMPLETED;
 }
@@ -427,9 +413,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-    SDL_FreeSurface( compareSurface );
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 }
@@ -452,9 +436,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-    SDL_FreeSurface( compareSurface );
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 }
@@ -477,9 +459,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-    SDL_FreeSurface( compareSurface );
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 }
@@ -503,9 +483,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-    SDL_FreeSurface( compareSurface );
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 }
@@ -528,9 +506,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-    SDL_FreeSurface( compareSurface );
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 }
@@ -553,9 +529,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-    SDL_FreeSurface( compareSurface );
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 }
@@ -578,9 +552,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-      SDL_FreeSurface( compareSurface );
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 }
@@ -603,9 +575,7 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
 
    /* Clean up. */
-   if (compareSurface != NULL) {
-     SDL_FreeSurface(compareSurface);
-   }
+   SDL_FreeSurface(compareSurface);
 
    return TEST_COMPLETED;
 
--- a/test/testshape.c	Thu Aug 29 08:29:21 2013 -0700
+++ b/test/testshape.c	Thu Aug 29 08:29:51 2013 -0700
@@ -90,8 +90,7 @@
         if(pictures[i].surface == NULL) {
             j = 0;
             for(j=0;j<num_pictures;j++)
-                if(pictures[j].surface != NULL)
-                    SDL_FreeSurface(pictures[j].surface);
+                SDL_FreeSurface(pictures[j].surface);
             SDL_free(pictures);
             SDL_VideoQuit();
             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file.");