Change winding_t and bspbrush_t to use flexible array members rather than size-1 arrays.
The arrays were always meant to be variably sized, and objects are only ever allocated dynamically. Object size computations are simplified with this change. Flexible arrays were introduced in C99, so this change means that we will require a C99-conforming compiler henceforth.
This commit is contained in:
parent
5064c1f163
commit
8875e2dd80
|
|
@ -26,7 +26,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
#include "aas_store.h"
|
#include "aas_store.h"
|
||||||
#include "aas_cfg.h"
|
#include "aas_cfg.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -425,7 +424,7 @@ bspbrush_t *AllocBrush (int numsides)
|
||||||
bspbrush_t *bb;
|
bspbrush_t *bb;
|
||||||
size_t c;
|
size_t c;
|
||||||
|
|
||||||
c = offsetof(bspbrush_t, sides[numsides]);
|
c = sizeof(*bb) + sizeof(*bb->sides) * numsides;
|
||||||
bb = GetMemory(c);
|
bb = GetMemory(c);
|
||||||
memset (bb, 0, c);
|
memset (bb, 0, c);
|
||||||
if (numthreads == 1)
|
if (numthreads == 1)
|
||||||
|
|
@ -488,7 +487,7 @@ bspbrush_t *CopyBrush (bspbrush_t *brush)
|
||||||
size_t size;
|
size_t size;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
size = offsetof(bspbrush_t, sides[brush->numsides]);
|
size = sizeof(*newbrush) + sizeof(*brush->sides) * brush->numsides;
|
||||||
|
|
||||||
newbrush = AllocBrush (brush->numsides);
|
newbrush = AllocBrush (brush->numsides);
|
||||||
memcpy (newbrush, brush, size);
|
memcpy (newbrush, brush, size);
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ winding_t *AllocWinding (int points)
|
||||||
winding_t *w;
|
winding_t *w;
|
||||||
int s;
|
int s;
|
||||||
|
|
||||||
s = sizeof(vec_t)*3*points + sizeof(int);
|
s = sizeof(*w) + sizeof(*w->p) * points;
|
||||||
w = GetMemory(s);
|
w = GetMemory(s);
|
||||||
memset(w, 0, s);
|
memset(w, 0, s);
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ void RemoveColinearPoints (winding_t *w)
|
||||||
if (numthreads == 1)
|
if (numthreads == 1)
|
||||||
c_removed += w->numpoints - nump;
|
c_removed += w->numpoints - nump;
|
||||||
w->numpoints = nump;
|
w->numpoints = nump;
|
||||||
memcpy (w->p, p, nump*sizeof(p[0]));
|
memcpy (w->p, p, nump * sizeof(*w->p));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -325,7 +325,7 @@ winding_t *CopyWinding (winding_t *w)
|
||||||
winding_t *c;
|
winding_t *c;
|
||||||
|
|
||||||
c = AllocWinding (w->numpoints);
|
c = AllocWinding (w->numpoints);
|
||||||
size = (int)((winding_t *)0)->p[w->numpoints];
|
size = sizeof(*w) + sizeof(*w->p) * w->numpoints;
|
||||||
memcpy (c, w, size);
|
memcpy (c, w, size);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int numpoints;
|
int numpoints;
|
||||||
vec3_t p[4]; //variable sized
|
vec3_t p[];
|
||||||
} winding_t;
|
} winding_t;
|
||||||
|
|
||||||
#define MAX_POINTS_ON_WINDING 96
|
#define MAX_POINTS_ON_WINDING 96
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ typedef struct bspbrush_s
|
||||||
int side, testside; // side of node during construction
|
int side, testside; // side of node during construction
|
||||||
mapbrush_t *original;
|
mapbrush_t *original;
|
||||||
int numsides;
|
int numsides;
|
||||||
side_t sides[6]; // variably sized
|
side_t sides[];
|
||||||
} bspbrush_t; //sizeof(bspbrush_t) = 44 + numsides * sizeof(side_t)
|
} bspbrush_t; //sizeof(bspbrush_t) = 44 + numsides * sizeof(side_t)
|
||||||
//bsp node
|
//bsp node
|
||||||
typedef struct node_s
|
typedef struct node_s
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user