diff LOD.cpp @ 2369:bddcaf5d5db2

removing non-nullptr conditions before frees, chaning 0 and NULL assignmnets to pointers to nullptr assignments
author Grumpy7
date Mon, 12 May 2014 01:50:32 +0200
parents bb9f180d50f6
children e07e297f292d
line wrap: on
line diff
--- a/LOD.cpp	Mon May 12 00:13:39 2014 +0200
+++ b/LOD.cpp	Mon May 12 01:50:32 2014 +0200
@@ -264,16 +264,16 @@
             pHardwareSprites = (Sprite *)malloc(1500*sizeof(Sprite));//0xEA60u
             for (i=0; i<1500;++i)
                 {
-                pHardwareSprites[i].pName=NULL;
-                pHardwareSprites[i].pTextureSurface=NULL;
-                pHardwareSprites[i].pTexture=NULL;
+                pHardwareSprites[i].pName=nullptr;
+                pHardwareSprites[i].pTextureSurface=nullptr;
+                pHardwareSprites[i].pTexture=nullptr;
                 } 
             }
         temp_sprite_hdr.uHeight = 0;
         temp_sprite_hdr.uPaletteId = 0;
         temp_sprite_hdr.word_1A = 0;
-        temp_sprite_hdr.pSpriteLines = 0;
-        temp_sprite_hdr.pDecompressedBytes = 0;
+        temp_sprite_hdr.pSpriteLines = nullptr;
+        temp_sprite_hdr.pDecompressedBytes = nullptr;
         sprite_file = FindContainer(pContainerName, 0);
         if ( !sprite_file )
             return -1;
@@ -349,11 +349,11 @@
           if ( v5 )
           {
             v5->Release();
-            v1->pHardwareSprites[v3].pTexture = 0;
+            v1->pHardwareSprites[v3].pTexture = nullptr;
           }
           v6 = (IDirectDrawSurface *)v1->pHardwareSprites[v3].pTextureSurface;
           v6->Release();
-          v1->pHardwareSprites[v3].pTextureSurface = 0;
+          v1->pHardwareSprites[v3].pTextureSurface = nullptr;
           pRenderer->MoveSpriteToDevice(&v1->pHardwareSprites[v3]);
         }
         ++v2;
@@ -391,7 +391,7 @@
           if ( v5 )
           {
             v5->Release();
-            v1->pHardwareSprites[v3].pTexture = 0;
+            v1->pHardwareSprites[v3].pTexture = nullptr;
           }
           v6 = v1->pHardwareSprites;
           if ( v6 )
@@ -400,7 +400,7 @@
             if ( v7 )
             {
               v7->Release();
-              v1->pHardwareSprites[v3].pTextureSurface = 0;
+              v1->pHardwareSprites[v3].pTextureSurface = nullptr;
             }
           }
         }
@@ -943,8 +943,8 @@
     this->uCurrentIndexDir = 0;
     free(pSubIndices);
     free(pRoot);
-    pSubIndices = NULL;
-    pRoot = NULL;
+    pSubIndices = nullptr;
+    pRoot = nullptr;
     fclose(pFile);
     isFileOpened = false;
     _6A0CA8_lod_unused = 0;
@@ -974,7 +974,7 @@
   fwrite(pHeader,sizeof(LOD::FileHeader), 1, pFile);
   fwrite(pDir, sizeof(LOD::Directory), 1, pFile);
   fclose(pFile);
-  pFile = 0;
+  pFile = nullptr;
   return 0;
 }
 
@@ -989,7 +989,7 @@
     uNumSubDirs = 0;
     uLODDataSize = 0;
     free(pSubIndices);
-    pSubIndices = NULL;
+    pSubIndices = nullptr;
   }
 }
 
@@ -1063,8 +1063,8 @@
     free(v1->pSpriteLines);
   }
   v1->word_1A = 0;
-  v1->pDecompressedBytes = 0;
-  v1->pSpriteLines = 0;
+  v1->pDecompressedBytes = nullptr;
+  v1->pSpriteLines = nullptr;
   v1->pName[0] = 0;
   v1->word_16 = 0;
   v1->uPaletteId = 0;
@@ -1077,8 +1077,7 @@
 //----- (00450D68) --------------------------------------------------------
 void Sprite::Release()
 {
-  if (pName)
-    free((void *)pName);
+  free((void *)pName);
   pName = nullptr;
 
   if (pTextureSurface)
@@ -1267,8 +1266,8 @@
     free(pDecompressedBytes);
     free(pSpriteLines);
   }
-  pDecompressedBytes = NULL;
-  pSpriteLines = NULL;
+  pDecompressedBytes = nullptr;
+  pSpriteLines = nullptr;
 }
 
 //----- (004623E5) --------------------------------------------------------
@@ -1333,12 +1332,9 @@
     }
     while ( (v2 & 0x80000000u) == 0 );
   }
-  if ( v1->pHardwareSurfaces )
-    free(v1->pHardwareSurfaces);
-  if ( v1->pHardwareTextures )
-    free(v1->pHardwareTextures);
-  if ( v1->ptr_011BB4 )
-    free(v1->ptr_011BB4);
+  free(v1->pHardwareSurfaces);
+  free(v1->pHardwareTextures);
+  free(v1->ptr_011BB4);
   //LOD::File::vdtor((LOD::File *)v1);
 }
 
@@ -1487,7 +1483,7 @@
     isFileOpened = false;
     fflush(pFile);
     fclose(pFile);
-    pFile = 0;
+    pFile = nullptr;
   }
   //else 
     //__debugbreak();
@@ -1712,7 +1708,7 @@
   {
     MessageBoxA(0, "Attempt to reset a LOD IObuffer!", "MM6", MB_ICONEXCLAMATION);
     free(pIOBuffer);
-    pIOBuffer = NULL;
+    pIOBuffer = nullptr;
     uIOBufferSize = 0;
   }
   if ( uBufferSize )
@@ -1810,9 +1806,9 @@
 {
   memset(pLODName, 0, 256);
   memset(pContainerName, 0, 16);
-  this->pFile = 0;
-  this->pSubIndices = 0;
-  this->pIOBuffer = 0;
+  this->pFile = nullptr;
+  this->pSubIndices = nullptr;
+  this->pIOBuffer = nullptr;
   this->isFileOpened = false;
   this->uIOBufferSize = 0;
   Close();