From f061ce9990880393675908f68e82b7694c12e9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20K=C3=B6ppe?= Date: Sun, 21 Jan 2018 02:03:31 +0000 Subject: [PATCH] Change winding_t, winding_accu_t and brush_t to use flexible array members rather than fixed-sized 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. --- tools/quake3/common/polylib.c | 4 ++-- tools/quake3/common/polylib.h | 4 ++-- tools/quake3/q3map2/brush.c | 4 ++-- tools/quake3/q3map2/q3map2.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/quake3/common/polylib.c b/tools/quake3/common/polylib.c index 216ba072..e71618bb 100644 --- a/tools/quake3/common/polylib.c +++ b/tools/quake3/common/polylib.c @@ -68,7 +68,7 @@ winding_t *AllocWinding( int points ){ c_peak_windings = c_active_windings; } } - s = sizeof( vec_t ) * 3 * points + sizeof( int ); + s = sizeof( *w ) + points * sizeof( *w->p ); w = safe_malloc( s ); memset( w, 0, s ); return w; @@ -96,7 +96,7 @@ winding_accu_t *AllocWindingAccu( int points ){ c_peak_windings = c_active_windings; } } - s = sizeof(*w) + (points > 4 ? sizeof(vec3_accu_t) * (points - 4) : 0); + s = sizeof( *w ) + points * sizeof( *w->p ); w = safe_malloc( s ); memset( w, 0, s ); return w; diff --git a/tools/quake3/common/polylib.h b/tools/quake3/common/polylib.h index 502a4a88..4b5afaa0 100644 --- a/tools/quake3/common/polylib.h +++ b/tools/quake3/common/polylib.h @@ -23,7 +23,7 @@ typedef struct { int numpoints; - vec3_t p[4]; // variable sized + vec3_t p[]; } winding_t; #define MAX_POINTS_ON_WINDING 64 @@ -65,7 +65,7 @@ void pw( winding_t *w ); typedef struct { int numpoints; - vec3_accu_t p[4]; // variable sized + vec3_accu_t p[]; } winding_accu_t; winding_accu_t *BaseWindingForPlaneAccu( vec3_t normal, vec_t dist ); diff --git a/tools/quake3/q3map2/brush.c b/tools/quake3/q3map2/brush.c index 2bd4c0cf..82e03690 100644 --- a/tools/quake3/q3map2/brush.c +++ b/tools/quake3/q3map2/brush.c @@ -93,7 +93,7 @@ brush_t *AllocBrush( int numSides ){ brush_t *bb; size_t c; - c = sizeof(*bb) + (numSides > 6 ? sizeof(side_t)*(numSides - 6) : 0); + c = sizeof( *bb ) + sizeof( *bb->sides ) * numSides; bb = safe_malloc( c ); memset( bb, 0, c ); if ( numthreads == 1 ) { @@ -1023,7 +1023,7 @@ void SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back ) for ( i = 0 ; i < 2 ; i++ ) { b[i] = AllocBrush( brush->numsides + 1 ); - memcpy( b[i], brush, sizeof( brush_t ) - sizeof( brush->sides ) ); + memcpy( b[i], brush, sizeof( brush_t ) ); b[i]->numsides = 0; b[i]->next = NULL; b[i]->original = brush->original; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index faef3024..4cca7101 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -893,7 +893,7 @@ typedef struct brush_s vec3_t mins, maxs; int numsides; - side_t sides[ 6 ]; /* variably sized */ + side_t sides[]; /* variably sized */ } brush_t;