shithub: choc

Download patch

ref: 1583812848e2704977df5a7a055610e5f63c8742
parent: 03771945c7fce016919fe53d60b6faff3fe09742
author: Simon Howard <[email protected]>
date: Tue Jan 27 16:21:56 EST 2009

Use sizeof() to calculate amounts to allocate, rather than hard-coded
sizes.

Subversion-branch: /branches/raven-branch
Subversion-revision: 1431

--- a/src/hexen/r_data.c
+++ b/src/hexen/r_data.c
@@ -349,13 +349,13 @@
     }
     numtextures = numtextures1 + numtextures2;
 
-    textures = Z_Malloc(numtextures * 4, PU_STATIC, 0);
-    texturecolumnlump = Z_Malloc(numtextures * 4, PU_STATIC, 0);
-    texturecolumnofs = Z_Malloc(numtextures * 4, PU_STATIC, 0);
-    texturecomposite = Z_Malloc(numtextures * 4, PU_STATIC, 0);
-    texturecompositesize = Z_Malloc(numtextures * 4, PU_STATIC, 0);
-    texturewidthmask = Z_Malloc(numtextures * 4, PU_STATIC, 0);
-    textureheight = Z_Malloc(numtextures * 4, PU_STATIC, 0);
+    textures = Z_Malloc(numtextures * sizeof(texture_t *), PU_STATIC, 0);
+    texturecolumnlump = Z_Malloc(numtextures * sizeof(short *), PU_STATIC, 0);
+    texturecolumnofs = Z_Malloc(numtextures * sizeof(short *), PU_STATIC, 0);
+    texturecomposite = Z_Malloc(numtextures * sizeof(byte *), PU_STATIC, 0);
+    texturecompositesize = Z_Malloc(numtextures * sizeof(int), PU_STATIC, 0);
+    texturewidthmask = Z_Malloc(numtextures * sizeof(int), PU_STATIC, 0);
+    textureheight = Z_Malloc(numtextures * sizeof(fixed_t), PU_STATIC, 0);
 
     totalwidth = 0;
 
@@ -392,8 +392,8 @@
                 I_Error("R_InitTextures: Missing patch in texture %s",
                         texture->name);
         }
-        texturecolumnlump[i] = Z_Malloc(texture->width * 2, PU_STATIC, 0);
-        texturecolumnofs[i] = Z_Malloc(texture->width * 2, PU_STATIC, 0);
+        texturecolumnlump[i] = Z_Malloc(texture->width * sizeof(short), PU_STATIC, 0);
+        texturecolumnofs[i] = Z_Malloc(texture->width * sizeof(short), PU_STATIC, 0);
         j = 1;
         while (j * 2 <= texture->width)
             j <<= 1;
@@ -420,7 +420,7 @@
 //
 // translation table for global animation
 //
-    texturetranslation = Z_Malloc((numtextures + 1) * 4, PU_STATIC, 0);
+    texturetranslation = Z_Malloc((numtextures + 1) * sizeof(int), PU_STATIC, 0);
     for (i = 0; i < numtextures; i++)
         texturetranslation[i] = i;
 }
@@ -443,7 +443,7 @@
     numflats = lastflat - firstflat + 1;
 
 // translation table for global animation
-    flattranslation = Z_Malloc((numflats + 1) * 4, PU_STATIC, 0);
+    flattranslation = Z_Malloc((numflats + 1) * sizeof(int), PU_STATIC, 0);
     for (i = 0; i < numflats; i++)
         flattranslation[i] = i;
 }
@@ -467,9 +467,9 @@
     firstspritelump = W_GetNumForName("S_START") + 1;
     lastspritelump = W_GetNumForName("S_END") - 1;
     numspritelumps = lastspritelump - firstspritelump + 1;
-    spritewidth = Z_Malloc(numspritelumps * 4, PU_STATIC, 0);
-    spriteoffset = Z_Malloc(numspritelumps * 4, PU_STATIC, 0);
-    spritetopoffset = Z_Malloc(numspritelumps * 4, PU_STATIC, 0);
+    spritewidth = Z_Malloc(numspritelumps * sizeof(fixed_t), PU_STATIC, 0);
+    spriteoffset = Z_Malloc(numspritelumps * sizeof(fixed_t), PU_STATIC, 0);
+    spritetopoffset = Z_Malloc(numspritelumps * sizeof(fixed_t), PU_STATIC, 0);
 
     for (i = 0; i < numspritelumps; i++)
     {