cleanup more offsetof usage

This commit is contained in:
Timothee Besset 2018-01-22 08:43:48 -06:00
parent 322935310e
commit 67fa177673
10 changed files with 5 additions and 24 deletions

View File

@ -131,9 +131,6 @@ extern vec_t g_MaxBrushSize;
#include "undo.h"
#include "glwidget.h"
// the dec offsetof macro doesn't work very well...
#define myoffsetof( type,identifier ) ( (size_t)&( (type *)0 )->identifier )
// set these before calling CheckParm
extern int myargc;
extern char **myargv;

View File

@ -61,9 +61,6 @@ typedef unsigned char byte;
#define SYS_ERR 3 // error
*/
// the dec offsetof macro doesnt work very well...
#define myoffsetof( type,identifier ) ( (size_t)& ( (type *)0 )->identifier )
#define SAFE_MALLOC
#ifdef SAFE_MALLOC
void *safe_malloc( size_t size );

View File

@ -48,10 +48,6 @@ typedef enum {false, true} qboolean;
typedef unsigned char byte;
#endif
// the dec offsetof macro doesnt work very well...
#define myoffsetof(type,identifier) ((size_t)&((type *)0)->identifier)
// set these before calling CheckParm
extern int myargc;
extern char **myargv;

View File

@ -39,10 +39,6 @@ typedef enum {false, true} qboolean;
typedef unsigned char byte;
#endif
// the dec offsetof macro doesn't work very well...
#define myoffsetof(type,identifier) ((size_t)&((type *)0)->identifier)
// set these before calling CheckParm
extern int myargc;
extern char **myargv;

View File

@ -66,8 +66,6 @@
#define SYS_WRN 2 // warnings
#define SYS_ERR 3 // error
*/
// the dec offsetof macro doesnt work very well...
#define myoffsetof( type,identifier ) ( (size_t)& ( (type *)0 )->identifier )
#define SAFE_MALLOC
#ifdef SAFE_MALLOC

View File

@ -56,9 +56,6 @@
#define MAX_OS_PATH 4096
#define MEM_BLOCKSIZE 4096
// the dec offsetof macro doesnt work very well...
#define myoffsetof( type,identifier ) ( (size_t)& ( (type *)0 )->identifier )
#define SAFE_MALLOC
#ifdef SAFE_MALLOC
void *safe_malloc( size_t size );

View File

@ -469,7 +469,7 @@ winding_t *CopyWinding( winding_t *w ){
}
c = AllocWinding( w->numpoints );
size = offsetof( winding_t, p ) + sizeof( *w->p ) * w->numpoints;
size = sizeof( *w ) + sizeof( *w->p ) * w->numpoints;
memcpy( c, w, size );
return c;
}

View File

@ -128,7 +128,7 @@ void FreeBrush( brush_t *b ){
}
/* ydnar: overwrite it */
memset( b, 0xFE, offsetof( brush_t, sides ) + sizeof( *b->sides ) * b->numsides );
memset( b, 0xFE, sizeof( *b ) + sizeof( *b->sides ) * b->numsides );
*( (unsigned int*) b ) = 0xFEFEFEFE;
/* free it */
@ -171,7 +171,7 @@ brush_t *CopyBrush( brush_t *brush ){
/* copy brush */
size = offsetof( brush_t, sides ) + sizeof( *brush->sides ) * brush->numsides;
size = sizeof( *brush ) + sizeof( *brush->sides ) * brush->numsides;
newBrush = AllocBrush( brush->numsides );
memcpy( newBrush, brush, size );

View File

@ -65,7 +65,7 @@ fixedWinding_t *NewFixedWinding( int points ){
Error( "NewWinding: %i points", points );
}
size = offsetof( fixedWinding_t, points ) + sizeof( *w->points ) * points;
size = sizeof( *w ) + sizeof( *w->points ) * points;
w = safe_malloc( size );
memset( w, 0, size );

View File

@ -1423,7 +1423,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, offsetof( fixedWinding_t, points ) + sizeof( *p->winding->points ) * p->winding->numpoints );
memcpy( &in, p->winding, sizeof( *p->winding ) + sizeof( *p->winding->points ) * p->winding->numpoints );
}
else{
memcpy( &in, p->winding, sizeof( fixedWinding_t ) );