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 "undo.h"
#include "glwidget.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 // set these before calling CheckParm
extern int myargc; extern int myargc;
extern char **myargv; extern char **myargv;

View file

@ -61,9 +61,6 @@ typedef unsigned char byte;
#define SYS_ERR 3 // error #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 #define SAFE_MALLOC
#ifdef SAFE_MALLOC #ifdef SAFE_MALLOC
void *safe_malloc( size_t size ); void *safe_malloc( size_t size );

View file

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

View file

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

View file

@ -66,8 +66,6 @@
#define SYS_WRN 2 // warnings #define SYS_WRN 2 // warnings
#define SYS_ERR 3 // error #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 #define SAFE_MALLOC
#ifdef SAFE_MALLOC #ifdef SAFE_MALLOC

View file

@ -56,9 +56,6 @@
#define MAX_OS_PATH 4096 #define MAX_OS_PATH 4096
#define MEM_BLOCKSIZE 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 #define SAFE_MALLOC
#ifdef SAFE_MALLOC #ifdef SAFE_MALLOC
void *safe_malloc( size_t size ); void *safe_malloc( size_t size );

View file

@ -469,7 +469,7 @@ winding_t *CopyWinding( winding_t *w ){
} }
c = AllocWinding( w->numpoints ); 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 ); memcpy( c, w, size );
return c; return c;
} }

View file

@ -128,7 +128,7 @@ void FreeBrush( brush_t *b ){
} }
/* ydnar: overwrite it */ /* 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; *( (unsigned int*) b ) = 0xFEFEFEFE;
/* free it */ /* free it */
@ -171,7 +171,7 @@ brush_t *CopyBrush( brush_t *brush ){
/* copy 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 ); newBrush = AllocBrush( brush->numsides );
memcpy( newBrush, brush, size ); memcpy( newBrush, brush, size );

View file

@ -65,7 +65,7 @@ fixedWinding_t *NewFixedWinding( int points ){
Error( "NewWinding: %i points", 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 ); w = safe_malloc( size );
memset( w, 0, size ); memset( w, 0, size );

View file

@ -1423,7 +1423,7 @@ void CreatePassages( int portalnum ){
/* ydnar: prefer correctness to stack overflow */ /* ydnar: prefer correctness to stack overflow */
//% memcpy( &in, p->winding, (int)((fixedWinding_t *)0)->points[p->winding->numpoints] ); //% memcpy( &in, p->winding, (int)((fixedWinding_t *)0)->points[p->winding->numpoints] );
if ( p->winding->numpoints <= MAX_POINTS_ON_FIXED_WINDING ) { 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{ else{
memcpy( &in, p->winding, sizeof( fixedWinding_t ) ); memcpy( &in, p->winding, sizeof( fixedWinding_t ) );