bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnubg] [PATCH] Correct data types in sizeof in board3d allocation


From: Russ Allbery
Subject: [Bug-gnubg] [PATCH] Correct data types in sizeof in board3d allocation
Date: Sat, 20 May 2006 20:31:34 -0700
User-agent: Gnus/5.110004 (No Gnus v0.4) XEmacs/21.4.18 (linux)

It looks like this was mostly fixed in CVS, but the data types chosen
still aren't quite correct.  Rule of thumb:  The type in sizeof() should
have one fewer * than the type of the variable to which the result of
malloc is being assigned.  Here's a patch:

Use the correct types in sizeof when allocating a 3d array.   The change
of float* to float** probably won't have any effect, but float and
float* may be different sizes.

Index: gnubg/board3d/misc3d.c
===================================================================
--- gnubg.orig/board3d/misc3d.c 2006-05-20 16:17:02.000000000 -0700
+++ gnubg/board3d/misc3d.c      2006-05-20 16:17:27.000000000 -0700
@@ -790,12 +790,12 @@ void initDT(diceTest* dt, int x, int y, 
 float ***Alloc3d(int x, int y, int z)
 {      /* Allocate 3d array */
        int i, j;
-       float ***array = (float ***)malloc(sizeof(float*) * x);
+       float ***array = (float ***)malloc(sizeof(float**) * x);
        for (i = 0; i < x; i++)
        {
                array[i] = (float **)malloc(sizeof(float*) * y);
                for (j = 0; j < y; j++)
-                       array[i][j] = (float *)malloc(sizeof(float*) * z);
+                       array[i][j] = (float *)malloc(sizeof(float) * z);
        }
        return array;
 }


-- 
Russ Allbery (address@hidden)             <http://www.eyrie.org/~eagle/>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]