fix new gcc build error: ‘N’ is not a constant expression, while using offsetof
This commit is contained in:
parent
7796044913
commit
4697d7940c
|
|
@ -89,6 +89,8 @@ void_ptr safe_calloc_info( size_t size, const char* info );
|
|||
#define safe_calloc_info( size, info ) calloc( 1, size )
|
||||
#endif /* SAFE_MALLOC */
|
||||
|
||||
#define offsetof_array( TYPE, ARRAY_MEMBER, ARRAY_SIZE ) ( offsetof( TYPE, ARRAY_MEMBER[0] ) + sizeof( TYPE::ARRAY_MEMBER[0] ) * ARRAY_SIZE )
|
||||
|
||||
|
||||
static inline bool strEmpty( const char* string ){
|
||||
return *string == '\0';
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ winding_t *AllocWinding( int points ){
|
|||
if ( points >= MAX_POINTS_ON_WINDING ) {
|
||||
Error( "AllocWinding failed: MAX_POINTS_ON_WINDING exceeded" );
|
||||
}
|
||||
return safe_calloc( offsetof( winding_t, p[points] ) );
|
||||
return safe_calloc( offsetof_array( winding_t, p, points ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -57,7 +57,7 @@ winding_accu_t *AllocWindingAccu( int points ){
|
|||
if ( points >= MAX_POINTS_ON_WINDING ) {
|
||||
Error( "AllocWindingAccu failed: MAX_POINTS_ON_WINDING exceeded" );
|
||||
}
|
||||
return safe_calloc( offsetof( winding_accu_t, p[points] ) );
|
||||
return safe_calloc( offsetof_array( winding_accu_t, p, points ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -362,7 +362,7 @@ winding_t *CopyWinding( const winding_t *w ){
|
|||
if ( !w ) {
|
||||
Error( "CopyWinding: winding is NULL" );
|
||||
}
|
||||
return void_ptr( memcpy( AllocWinding( w->numpoints ), w, offsetof( winding_t, p[w->numpoints] ) ) );
|
||||
return void_ptr( memcpy( AllocWinding( w->numpoints ), w, offsetof_array( winding_t, p, w->numpoints ) ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -375,7 +375,7 @@ winding_accu_t *CopyWindingAccuIncreaseSizeAndFreeOld( winding_accu_t *w ){
|
|||
Error( "CopyWindingAccuIncreaseSizeAndFreeOld: winding is NULL" );
|
||||
}
|
||||
|
||||
winding_accu_t *c = void_ptr( memcpy( AllocWindingAccu( w->numpoints + 1 ), w, offsetof( winding_accu_t, p[w->numpoints] ) ) );
|
||||
winding_accu_t *c = void_ptr( memcpy( AllocWindingAccu( w->numpoints + 1 ), w, offsetof_array( winding_accu_t, p, w->numpoints ) ) );
|
||||
FreeWindingAccu( w );
|
||||
return c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ struct StrList
|
|||
};
|
||||
|
||||
static inline StrList* StrList_allocate( size_t strNum ){
|
||||
StrList* ret = safe_calloc( offsetof( StrList, s[strNum] ) );
|
||||
StrList* ret = safe_calloc( offsetof_array( StrList, s, strNum ) );
|
||||
ret->n = 0;
|
||||
ret->max = strNum;
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ int CountBrushList( brush_t *brushes ){
|
|||
*/
|
||||
|
||||
brush_t *AllocBrush( int numSides ){
|
||||
return safe_calloc( offsetof( brush_t, sides[numSides] ) );
|
||||
return safe_calloc( offsetof_array( brush_t, sides, numSides ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ void FreeBrush( brush_t *b ){
|
|||
}
|
||||
|
||||
/* ydnar: overwrite it */
|
||||
memset( b, 0xFE, offsetof( brush_t, sides[b->numsides] ) );
|
||||
memset( b, 0xFE, offsetof_array( brush_t, sides, b->numsides ) );
|
||||
*( (unsigned int*) b ) = 0xFEFEFEFE;
|
||||
|
||||
/* free it */
|
||||
|
|
@ -148,7 +148,7 @@ void FreeBrushList( brush_t *brushes ){
|
|||
brush_t *CopyBrush( const brush_t *brush ){
|
||||
/* copy brush */
|
||||
brush_t *newBrush = AllocBrush( brush->numsides );
|
||||
memcpy( newBrush, brush, offsetof( brush_t, sides[brush->numsides] ) );
|
||||
memcpy( newBrush, brush, offsetof_array( brush_t, sides, brush->numsides ) );
|
||||
|
||||
/* ydnar: nuke linked list */
|
||||
newBrush->next = NULL;
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ visPlane_t PlaneFromWinding( const fixedWinding_t *w ){
|
|||
ydnar: altered this a bit to reconcile multiply-defined winding_t
|
||||
*/
|
||||
|
||||
fixedWinding_t *NewFixedWinding( int points ){
|
||||
if ( points > MAX_POINTS_ON_WINDING ) {
|
||||
Error( "NewWinding: %i points", points );
|
||||
fixedWinding_t *NewFixedWinding( int numpoints ){
|
||||
if ( numpoints > MAX_POINTS_ON_WINDING ) {
|
||||
Error( "NewWinding: %i points", numpoints );
|
||||
}
|
||||
return safe_calloc( offsetof( fixedWinding_t, points[points] ) );
|
||||
return safe_calloc( offsetof_array( fixedWinding_t, points, numpoints ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1332,8 +1332,7 @@ void CreatePassages( int portalnum ){
|
|||
/* ydnar: prefer correctness to stack overflow */
|
||||
//% memcpy( &in, p->winding, (int)((fixedWinding_t *)0)->points[p->winding->numpoints] );
|
||||
if ( p->winding->numpoints <= MAX_POINTS_ON_FIXED_WINDING ) {
|
||||
memcpy( &in, p->winding, (size_t)&( ( (fixedWinding_t *)0 )->points[p->winding->numpoints] ) );
|
||||
// memcpy( &in, p->winding, offsetof( fixedWinding_t, points[p->winding->numpoints] ) );
|
||||
memcpy( &in, p->winding, offsetof_array( fixedWinding_t, points, p->winding->numpoints ) );
|
||||
}
|
||||
else{
|
||||
memcpy( &in, p->winding, sizeof( fixedWinding_t ) );
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user