fix the build

This commit is contained in:
Garux 2021-01-16 15:10:59 +03:00
parent fafa271a46
commit 13524d59ef
44 changed files with 222 additions and 189 deletions

View File

@ -94,6 +94,8 @@ bool VectorCompare( const vec3_t v1, const vec3_t v2 );
bool VectorIsOnAxis( vec3_t v ); bool VectorIsOnAxis( vec3_t v );
bool VectorIsOnAxialPlane( vec3_t v ); bool VectorIsOnAxialPlane( vec3_t v );
void MakeNormalVectors( vec3_t forward, vec3_t right, vec3_t up );
vec_t VectorLength( const vec3_t v ); vec_t VectorLength( const vec3_t v );
void VectorMA( const vec3_t va, vec_t scale, const vec3_t vb, vec3_t vc ); void VectorMA( const vec3_t va, vec_t scale, const vec3_t vb, vec3_t vc );

View File

@ -214,7 +214,7 @@ polyset_t *ASE_GetSurfaceAnimation( int which, int *pNumFrames, int skipFrameSta
*pNumFrames = numFramesToKeep; *pNumFrames = numFramesToKeep;
psets = calloc( sizeof( polyset_t ) * numFramesToKeep, 1 ); psets = safe_calloc( sizeof( polyset_t ) * numFramesToKeep );
for ( f = 0, i = 0; i < numFramesInAnimation; i++ ) for ( f = 0, i = 0; i < numFramesInAnimation; i++ )
{ {
@ -230,7 +230,7 @@ polyset_t *ASE_GetSurfaceAnimation( int which, int *pNumFrames, int skipFrameSta
strcpy( psets[f].name, pObject->name ); strcpy( psets[f].name, pObject->name );
strcpy( psets[f].materialname, ase.materials[pObject->materialRef].name ); strcpy( psets[f].materialname, ase.materials[pObject->materialRef].name );
psets[f].triangles = calloc( sizeof( triangle_t ) * pObject->anim.frames[i].numFaces, 1 ); psets[f].triangles = safe_calloc( sizeof( triangle_t ) * pObject->anim.frames[i].numFaces );
psets[f].numtriangles = pObject->anim.frames[i].numFaces; psets[f].numtriangles = pObject->anim.frames[i].numFaces;
for ( t = 0; t < pObject->anim.frames[i].numFaces; t++ ) for ( t = 0; t < pObject->anim.frames[i].numFaces; t++ )
@ -632,25 +632,25 @@ static void ASE_KeyMESH( const char *token ){
VERBOSE( ( ".....num tvertexes: %d\n", pMesh->numTVertexes ) ); VERBOSE( ( ".....num tvertexes: %d\n", pMesh->numTVertexes ) );
} }
else if ( strEqual( token, "*MESH_VERTEX_LIST" ) ) { else if ( strEqual( token, "*MESH_VERTEX_LIST" ) ) {
pMesh->vertexes = calloc( sizeof( aseVertex_t ) * pMesh->numVertexes, 1 ); pMesh->vertexes = safe_calloc( sizeof( aseVertex_t ) * pMesh->numVertexes );
pMesh->currentVertex = 0; pMesh->currentVertex = 0;
VERBOSE( ( ".....parsing MESH_VERTEX_LIST\n" ) ); VERBOSE( ( ".....parsing MESH_VERTEX_LIST\n" ) );
ASE_ParseBracedBlock( ASE_KeyMESH_VERTEX_LIST ); ASE_ParseBracedBlock( ASE_KeyMESH_VERTEX_LIST );
} }
else if ( strEqual( token, "*MESH_TVERTLIST" ) ) { else if ( strEqual( token, "*MESH_TVERTLIST" ) ) {
pMesh->currentVertex = 0; pMesh->currentVertex = 0;
pMesh->tvertexes = calloc( sizeof( aseTVertex_t ) * pMesh->numTVertexes, 1 ); pMesh->tvertexes = safe_calloc( sizeof( aseTVertex_t ) * pMesh->numTVertexes );
VERBOSE( ( ".....parsing MESH_TVERTLIST\n" ) ); VERBOSE( ( ".....parsing MESH_TVERTLIST\n" ) );
ASE_ParseBracedBlock( ASE_KeyMESH_TVERTLIST ); ASE_ParseBracedBlock( ASE_KeyMESH_TVERTLIST );
} }
else if ( strEqual( token, "*MESH_FACE_LIST" ) ) { else if ( strEqual( token, "*MESH_FACE_LIST" ) ) {
pMesh->faces = calloc( sizeof( aseFace_t ) * pMesh->numFaces, 1 ); pMesh->faces = safe_calloc( sizeof( aseFace_t ) * pMesh->numFaces );
pMesh->currentFace = 0; pMesh->currentFace = 0;
VERBOSE( ( ".....parsing MESH_FACE_LIST\n" ) ); VERBOSE( ( ".....parsing MESH_FACE_LIST\n" ) );
ASE_ParseBracedBlock( ASE_KeyMESH_FACE_LIST ); ASE_ParseBracedBlock( ASE_KeyMESH_FACE_LIST );
} }
else if ( strEqual( token, "*MESH_TFACELIST" ) ) { else if ( strEqual( token, "*MESH_TFACELIST" ) ) {
pMesh->tfaces = calloc( sizeof( aseFace_t ) * pMesh->numFaces, 1 ); pMesh->tfaces = safe_calloc( sizeof( aseFace_t ) * pMesh->numFaces );
pMesh->currentFace = 0; pMesh->currentFace = 0;
VERBOSE( ( ".....parsing MESH_TFACE_LIST\n" ) ); VERBOSE( ( ".....parsing MESH_TFACE_LIST\n" ) );
ASE_ParseBracedBlock( ASE_KeyTFACE_LIST ); ASE_ParseBracedBlock( ASE_KeyTFACE_LIST );

View File

@ -20,7 +20,7 @@
*/ */
#include "../common/cmdlib.h" #include "cmdlib.h"
#include "mathlib.h" #include "mathlib.h"
#include "polyset.h" #include "polyset.h"

View File

@ -126,7 +126,7 @@ void IncDrawVerts(){
numDrawVertsBuffer = MAX_MAP_DRAW_VERTS; numDrawVertsBuffer = MAX_MAP_DRAW_VERTS;
} }
drawVerts = realloc( drawVerts, sizeof( drawVert_t ) * numDrawVertsBuffer ); drawVerts = void_ptr( realloc( drawVerts, sizeof( drawVert_t ) * numDrawVertsBuffer ) );
if ( !drawVerts ) { if ( !drawVerts ) {
Error( "realloc() failed (IncDrawVerts)" ); Error( "realloc() failed (IncDrawVerts)" );

View File

@ -47,7 +47,7 @@
#ifdef SAFE_MALLOC #ifdef SAFE_MALLOC
// FIXME switch to -std=c99 or above to use proper %zu format specifier for size_t // FIXME switch to -std=c99 or above to use proper %zu format specifier for size_t
void *safe_malloc( size_t size ){ void_ptr safe_malloc( size_t size ){
void *p = malloc( size ); void *p = malloc( size );
if ( !p ) { if ( !p ) {
Error( "safe_malloc failed on allocation of %lu bytes", (unsigned long)size ); Error( "safe_malloc failed on allocation of %lu bytes", (unsigned long)size );
@ -55,7 +55,7 @@ void *safe_malloc( size_t size ){
return p; return p;
} }
void *safe_malloc_info( size_t size, const char* info ){ void_ptr safe_malloc_info( size_t size, const char* info ){
void *p = malloc( size ); void *p = malloc( size );
if ( !p ) { if ( !p ) {
Error( "%s: safe_malloc failed on allocation of %lu bytes", info, (unsigned long)size ); Error( "%s: safe_malloc failed on allocation of %lu bytes", info, (unsigned long)size );
@ -63,7 +63,7 @@ void *safe_malloc_info( size_t size, const char* info ){
return p; return p;
} }
void *safe_calloc( size_t size ){ void_ptr safe_calloc( size_t size ){
void *p = calloc( 1, size ); void *p = calloc( 1, size );
if ( !p ) { if ( !p ) {
Error( "safe_calloc failed on allocation of %lu bytes", (unsigned long)size ); Error( "safe_calloc failed on allocation of %lu bytes", (unsigned long)size );
@ -71,7 +71,7 @@ void *safe_calloc( size_t size ){
return p; return p;
} }
void *safe_calloc_info( size_t size, const char* info ){ void_ptr safe_calloc_info( size_t size, const char* info ){
void *p = calloc( 1, size ); void *p = calloc( 1, size );
if ( !p ) { if ( !p ) {
Error( "%s: safe_calloc failed on allocation of %lu bytes", info, (unsigned long)size ); Error( "%s: safe_calloc failed on allocation of %lu bytes", info, (unsigned long)size );
@ -327,7 +327,7 @@ int FileTime( const char *path ){
//http://stackoverflow.com/questions/27303062/strstr-function-like-that-ignores-upper-or-lower-case //http://stackoverflow.com/questions/27303062/strstr-function-like-that-ignores-upper-or-lower-case
//chux: Somewhat tricky to match the corner cases of strstr() with inputs like "x","", "","x", "","" //chux: Somewhat tricky to match the corner cases of strstr() with inputs like "x","", "","x", "",""
char *strIstr( const char* haystack, const char* needle ) { const char *strIstr( const char* haystack, const char* needle ) {
do { do {
const char* h = haystack; const char* h = haystack;
const char* n = needle; const char* n = needle;
@ -342,6 +342,10 @@ char *strIstr( const char* haystack, const char* needle ) {
return NULL; return NULL;
} }
char *strIstr( char* haystack, const char* needle ) {
return const_cast<char*>( strIstr( const_cast<const char*>( haystack ), needle ) );
}
/* /*
* Copy src to string dst of size size. At most size-1 characters * Copy src to string dst of size size. At most size-1 characters
* will be copied. Always NUL terminates (unless size == 0). * will be copied. Always NUL terminates (unless size == 0).
@ -571,7 +575,7 @@ bool path_is_absolute( const char* path ){
} }
/// \brief Returns a pointer to the last slash or to terminating null character if not found. /// \brief Returns a pointer to the last slash or to terminating null character if not found.
char* path_get_last_separator( const char* path ){ const char* path_get_last_separator( const char* path ){
const char *end = path + strlen( path ); const char *end = path + strlen( path );
const char *src = end; const char *src = end;
@ -582,8 +586,12 @@ char* path_get_last_separator( const char* path ){
return end; return end;
} }
char* path_get_last_separator( char* path ){
return const_cast<char*>( path_get_last_separator( const_cast<const char*>( path ) ) );
}
/// \brief Returns a pointer to the first character of the filename component of \p path. /// \brief Returns a pointer to the first character of the filename component of \p path.
char* path_get_filename_start( const char* path ){ const char* path_get_filename_start( const char* path ){
const char *src = path + strlen( path ); const char *src = path + strlen( path );
while ( src != path && !path_separator( src[-1] ) ){ while ( src != path && !path_separator( src[-1] ) ){
@ -592,8 +600,12 @@ char* path_get_filename_start( const char* path ){
return src; return src;
} }
char* path_get_filename_start( char* path ){
return const_cast<char*>( path_get_filename_start( const_cast<const char*>( path ) ) );
}
/// \brief Returns a pointer to the character after the end of the filename component of \p path - either the extension separator or the terminating null character. /// \brief Returns a pointer to the character after the end of the filename component of \p path - either the extension separator or the terminating null character.
char* path_get_filename_base_end( const char* path ){ const char* path_get_filename_base_end( const char* path ){
const char *end = path + strlen( path ); const char *end = path + strlen( path );
const char *src = end; const char *src = end;
@ -604,9 +616,12 @@ char* path_get_filename_base_end( const char* path ){
return end; return end;
} }
char* path_get_filename_base_end( char* path ){
return const_cast<char*>( path_get_filename_base_end( const_cast<const char*>( path ) ) );
}
/// \brief Returns a pointer to the first character of the file extension of \p path, or to terminating null character if not found. /// \brief Returns a pointer to the first character of the file extension of \p path, or to terminating null character if not found.
char* path_get_extension( const char* path ){ const char* path_get_extension( const char* path ){
const char *end = path + strlen( path ); const char *end = path + strlen( path );
const char *src = end; const char *src = end;
@ -617,6 +632,10 @@ char* path_get_extension( const char* path ){
return end; return end;
} }
char* path_get_extension( char* path ){
return const_cast<char*>( path_get_extension( const_cast<const char*>( path ) ) );
}
/// \brief Appends trailing slash, unless \p path is empty or already has slash. /// \brief Appends trailing slash, unless \p path is empty or already has slash.
void path_add_slash( char *path ){ void path_add_slash( char *path ){
char* end = path + strlen( path ); char* end = path + strlen( path );

View File

@ -62,10 +62,24 @@
#define SAFE_MALLOC #define SAFE_MALLOC
#ifdef SAFE_MALLOC #ifdef SAFE_MALLOC
void *safe_malloc( size_t size );
void *safe_malloc_info( size_t size, const char* info ); class void_ptr
void *safe_calloc( size_t size ); {
void *safe_calloc_info( size_t size, const char* info ); private:
void *ptr;
public:
void_ptr() = delete;
void_ptr( void *p ) : ptr( p ) {}
template<typename T>
operator T*() const {
return static_cast<T*>( ptr );
}
};
void_ptr safe_malloc( size_t size );
void_ptr safe_malloc_info( size_t size, const char* info );
void_ptr safe_calloc( size_t size );
void_ptr safe_calloc_info( size_t size, const char* info );
#else #else
#define safe_malloc( size ) malloc( size ) #define safe_malloc( size ) malloc( size )
#define safe_malloc_info( size, info ) malloc( size ) #define safe_malloc_info( size, info ) malloc( size )
@ -90,9 +104,10 @@ static inline char *strLower( char *string ){
} }
static inline char *copystring( const char *src ){ // version of strdup() with safe_malloc() static inline char *copystring( const char *src ){ // version of strdup() with safe_malloc()
const size_t size = strlen( src ) + 1; const size_t size = strlen( src ) + 1;
return memcpy( safe_malloc( size ), src, size ); return void_ptr( memcpy( safe_malloc( size ), src, size ) );
} }
char* strIstr( const char* haystack, const char* needle ); const char* strIstr( const char* haystack, const char* needle );
char* strIstr( char* haystack, const char* needle );
#ifdef WIN32 #ifdef WIN32
#define Q_stricmp stricmp #define Q_stricmp stricmp
#define Q_strnicmp strnicmp #define Q_strnicmp strnicmp
@ -174,10 +189,14 @@ static inline bool path_separator( const char c ){
return c == '/' || c == '\\'; return c == '/' || c == '\\';
} }
bool path_is_absolute( const char* path ); bool path_is_absolute( const char* path );
char* path_get_last_separator( const char* path ); const char* path_get_last_separator( const char* path );
char* path_get_filename_start( const char* path ); char* path_get_last_separator( char* path );
char* path_get_filename_base_end( const char* path ); const char* path_get_filename_start( const char* path );
char* path_get_extension( const char* path ); char* path_get_filename_start( char* path );
const char* path_get_filename_base_end( const char* path );
char* path_get_filename_base_end( char* path );
const char* path_get_extension( const char* path );
char* path_get_extension( char* path );
void path_add_slash( char *path ); void path_add_slash( char *path );
void path_set_extension( char *path, const char *extension ); void path_set_extension( char *path, const char *extension );
void DefaultExtension( char *path, const char *extension ); void DefaultExtension( char *path, const char *extension );

View File

@ -140,7 +140,7 @@ void xml_SendNode( xmlNodePtr node ){
} }
} }
void xml_Select( char *msg, int entitynum, int brushnum, bool bError ){ void xml_Select( const char *msg, int entitynum, int brushnum, bool bError ){
xmlNodePtr node, select; xmlNodePtr node, select;
char buf[1024]; char buf[1024];
char level[2]; char level[2];
@ -168,7 +168,7 @@ void xml_Select( char *msg, int entitynum, int brushnum, bool bError ){
} }
} }
void xml_Point( char *msg, vec3_t pt ){ void xml_Point( const char *msg, vec3_t pt ){
xmlNodePtr node, point; xmlNodePtr node, point;
char buf[1024]; char buf[1024];
char level[2]; char level[2];
@ -190,7 +190,7 @@ void xml_Point( char *msg, vec3_t pt ){
} }
#define WINDING_BUFSIZE 2048 #define WINDING_BUFSIZE 2048
void xml_Winding( char *msg, vec3_t p[], int numpoints, bool die ){ void xml_Winding( const char *msg, vec3_t p[], int numpoints, bool die ){
xmlNodePtr node, winding; xmlNodePtr node, winding;
char buf[WINDING_BUFSIZE]; char buf[WINDING_BUFSIZE];
char smlbuf[128]; char smlbuf[128];
@ -201,7 +201,7 @@ void xml_Winding( char *msg, vec3_t p[], int numpoints, bool die ){
xmlNodeAddContent( node, (const xmlChar*)msg ); xmlNodeAddContent( node, (const xmlChar*)msg );
level[0] = (int)'0' + SYS_ERR; level[0] = (int)'0' + SYS_ERR;
level[1] = 0; level[1] = 0;
xmlSetProp( node, (xmlChar*)"level", (const xmlChar *)level ); xmlSetProp( node, (const xmlChar*)"level", (const xmlChar *)level );
// a 'winding' node // a 'winding' node
sprintf( buf, "%i ", numpoints ); sprintf( buf, "%i ", numpoints );
for ( i = 0; i < numpoints; i++ ) for ( i = 0; i < numpoints; i++ )

View File

@ -31,11 +31,11 @@ xmlNodePtr xml_NodeForVec( vec3_t v );
void xml_SendNode( xmlNodePtr node ); void xml_SendNode( xmlNodePtr node );
// print a message in q3map output and send the corresponding select information down the xml stream // print a message in q3map output and send the corresponding select information down the xml stream
// bError: do we end with an error on this one or do we go ahead? // bError: do we end with an error on this one or do we go ahead?
void xml_Select( char *msg, int entitynum, int brushnum, bool bError ); void xml_Select( const char *msg, int entitynum, int brushnum, bool bError );
// end q3map with an error message and send a point information in the xml stream // end q3map with an error message and send a point information in the xml stream
// note: we might want to add a boolean to use this as a warning or an error thing.. // note: we might want to add a boolean to use this as a warning or an error thing..
void xml_Winding( char *msg, vec3_t p[], int numpoints, bool die ); void xml_Winding( const char *msg, vec3_t p[], int numpoints, bool die );
void xml_Point( char *msg, vec3_t pt ); void xml_Point( const char *msg, vec3_t pt );
void Broadcast_Setup( const char *dest ); void Broadcast_Setup( const char *dest );
void Broadcast_Shutdown(); void Broadcast_Shutdown();

View File

@ -42,6 +42,8 @@
#include <jpeglib.h> #include <jpeglib.h>
#include <jerror.h> #include <jerror.h>
#include "cmdlib.h"
/* Expanded data source object for stdio input */ /* Expanded data source object for stdio input */
typedef struct { typedef struct {
@ -358,7 +360,7 @@ int LoadJPGBuff( void *src_buffer, int src_size, unsigned char **pic, int *width
size = cinfo.output_width * cinfo.output_height * 4; size = cinfo.output_width * cinfo.output_height * 4;
*width = cinfo.output_width; *width = cinfo.output_width;
*height = cinfo.output_height; *height = cinfo.output_height;
*pic = calloc( 1, size + 1 ); *pic = safe_calloc( size + 1 );
buffer = ( *cinfo.mem->alloc_sarray )( ( j_common_ptr ) & cinfo, JPOOL_IMAGE, row_stride, 1 ); buffer = ( *cinfo.mem->alloc_sarray )( ( j_common_ptr ) & cinfo, JPOOL_IMAGE, row_stride, 1 );

View File

@ -65,7 +65,7 @@ mutex_t *MutexAlloc( void ){
} }
crit = (CRITICAL_SECTION *) safe_malloc( sizeof( CRITICAL_SECTION ) ); crit = (CRITICAL_SECTION *) safe_malloc( sizeof( CRITICAL_SECTION ) );
InitializeCriticalSection( crit ); InitializeCriticalSection( crit );
return (void *) crit; return reinterpret_cast<mutex_t *>( crit );
} }
#endif #endif

View File

@ -413,7 +413,7 @@ winding_t *CopyWinding( const winding_t *w ){
if ( !w ) { if ( !w ) {
Error( "CopyWinding: winding is NULL" ); Error( "CopyWinding: winding is NULL" );
} }
return memcpy( AllocWinding( w->numpoints ), w, offsetof( winding_t, p[w->numpoints] ) ); return void_ptr( memcpy( AllocWinding( w->numpoints ), w, offsetof( winding_t, p[w->numpoints] ) ) );
} }
/* /*
@ -426,7 +426,7 @@ winding_accu_t *CopyWindingAccuIncreaseSizeAndFreeOld( winding_accu_t *w ){
Error( "CopyWindingAccuIncreaseSizeAndFreeOld: winding is NULL" ); Error( "CopyWindingAccuIncreaseSizeAndFreeOld: winding is NULL" );
} }
winding_accu_t *c = 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( winding_accu_t, p[w->numpoints] ) ) );
FreeWindingAccu( w ); FreeWindingAccu( w );
return c; return c;
} }

View File

@ -81,7 +81,7 @@ void AddScriptToStack( const char *filename, int index ){
Sys_Printf( "entering %s\n", script->filename ); Sys_Printf( "entering %s\n", script->filename );
} }
script->buffer = buffer; script->buffer = void_ptr( buffer );
script->line = 1; script->line = 1;
script->script_p = script->buffer; script->script_p = script->buffer;
script->end_p = script->buffer + size; script->end_p = script->buffer + size;
@ -356,7 +356,7 @@ bool TokenAvailable( void ) {
//===================================================================== //=====================================================================
void MatchToken( char *match ) { void MatchToken( const char *match ) {
GetToken( true ); GetToken( true );
if ( !strEqual( token, match ) ) { if ( !strEqual( token, match ) ) {

View File

@ -45,7 +45,7 @@ bool GetToken( bool crossline );
void UnGetToken( void ); void UnGetToken( void );
bool TokenAvailable( void ); bool TokenAvailable( void );
void MatchToken( char *match ); void MatchToken( const char *match );
void Parse1DMatrix( int x, vec_t *m ); void Parse1DMatrix( int x, vec_t *m );
void Parse2DMatrix( int y, int x, vec_t *m ); void Parse2DMatrix( int y, int x, vec_t *m );

View File

@ -575,7 +575,7 @@ void RunThreadsOn( int workcnt, bool showpacifier, void ( *func )( int ) ){
for ( i = 0 ; i < numthreads ; i++ ) for ( i = 0 ; i < numthreads ; i++ )
{ {
/* Default pthread attributes: joinable & non-realtime scheduling */ /* Default pthread attributes: joinable & non-realtime scheduling */
if ( pthread_create( &work_threads[i], &attr, (void*)func, (void*)(size_t)i ) != 0 ) { if ( pthread_create( &work_threads[i], &attr, (void *(*)(void *)) func, (void*)(size_t)i ) != 0 ) {
Error( "pthread_create failed" ); Error( "pthread_create failed" );
} }
} }

View File

@ -120,8 +120,8 @@ void TRI_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets )
Error( "%s is not a Alias object separated triangle file, magic number is wrong.", filename ); Error( "%s is not a Alias object separated triangle file, magic number is wrong.", filename );
} }
pPSET = calloc( 1, POLYSET_MAXPOLYSETS * sizeof( polyset_t ) ); pPSET = safe_calloc( POLYSET_MAXPOLYSETS * sizeof( polyset_t ) );
ptri = calloc( 1, POLYSET_MAXTRIANGLES * sizeof( triangle_t ) ); ptri = safe_calloc( POLYSET_MAXTRIANGLES * sizeof( triangle_t ) );
*ppPSET = pPSET; *ppPSET = pPSET;

View File

@ -2919,7 +2919,7 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
case 3: /* illegal */ case 3: /* illegal */
DUMPBITS(3) DUMPBITS(3)
s->mode = BAD; s->mode = BAD;
z->msg = (char*)"invalid block type"; z->msg = "invalid block type";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
LEAVE LEAVE
} }
@ -2929,7 +2929,7 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
if ((((~b) >> 16) & 0xffff) != (b & 0xffff)) if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
{ {
s->mode = BAD; s->mode = BAD;
z->msg = (char*)"invalid stored block lengths"; z->msg = "invalid stored block lengths";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
LEAVE LEAVE
} }
@ -2962,7 +2962,7 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
{ {
s->mode = BAD; s->mode = BAD;
z->msg = (char*)"too many length or distance symbols"; z->msg = "too many length or distance symbols";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
LEAVE LEAVE
} }
@ -3032,7 +3032,7 @@ int inflate_blocks(inflate_blocks_statef *s, z_streamp z, int r)
{ {
ZFREE(z, s->sub.trees.blens); ZFREE(z, s->sub.trees.blens);
s->mode = BAD; s->mode = BAD;
z->msg = (char*)"invalid bit length repeat"; z->msg = "invalid bit length repeat";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
LEAVE LEAVE
} }
@ -3320,16 +3320,16 @@ static int huft_build(uInt *b, uInt n, uInt s, const uInt *d, const uInt *e, inf
uInt f; /* i repeats in table every f entries */ uInt f; /* i repeats in table every f entries */
int g; /* maximum code length */ int g; /* maximum code length */
int h; /* table level */ int h; /* table level */
register uInt i; /* counter, current code */ uInt i; /* counter, current code */
register uInt j; /* counter */ uInt j; /* counter */
register int k; /* number of bits in current code */ int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */ int l; /* bits per table (returned in m) */
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */ uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
register uInt *p; /* pointer into c[], b[], or v[] */ uInt *p; /* pointer into c[], b[], or v[] */
inflate_huft *q; /* points to current table */ inflate_huft *q; /* points to current table */
struct inflate_huft_s r; /* table entry for structure assignment */ struct inflate_huft_s r; /* table entry for structure assignment */
inflate_huft *u[BMAX]; /* table stack */ inflate_huft *u[BMAX]; /* table stack */
register int w; /* bits before this table == (l * h) */ int w; /* bits before this table == (l * h) */
uInt x[BMAX+1]; /* bit offsets, then code stack */ uInt x[BMAX+1]; /* bit offsets, then code stack */
uInt *xp; /* pointer into x */ uInt *xp; /* pointer into x */
int y; /* number of dummy codes added */ int y; /* number of dummy codes added */
@ -3515,10 +3515,10 @@ int inflate_trees_bits(uInt *c, uInt *bb, inflate_huft * *tb, inflate_huft *hp,
r = huft_build(c, 19, 19, (uInt*)Z_NULL, (uInt*)Z_NULL, r = huft_build(c, 19, 19, (uInt*)Z_NULL, (uInt*)Z_NULL,
tb, bb, hp, &hn, v); tb, bb, hp, &hn, v);
if (r == Z_DATA_ERROR) if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed dynamic bit lengths tree"; z->msg = "oversubscribed dynamic bit lengths tree";
else if (r == Z_BUF_ERROR || *bb == 0) else if (r == Z_BUF_ERROR || *bb == 0)
{ {
z->msg = (char*)"incomplete dynamic bit lengths tree"; z->msg = "incomplete dynamic bit lengths tree";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
} }
ZFREE(z, v); ZFREE(z, v);
@ -3551,10 +3551,10 @@ int inflate_trees_dynamic(uInt nl, uInt nd, uInt *c, uInt *bl, uInt *bd, inflate
if (r != Z_OK || *bl == 0) if (r != Z_OK || *bl == 0)
{ {
if (r == Z_DATA_ERROR) if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed literal/length tree"; z->msg = "oversubscribed literal/length tree";
else if (r != Z_MEM_ERROR) else if (r != Z_MEM_ERROR)
{ {
z->msg = (char*)"incomplete literal/length tree"; z->msg = "incomplete literal/length tree";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
} }
ZFREE(z, v); ZFREE(z, v);
@ -3566,18 +3566,18 @@ int inflate_trees_dynamic(uInt nl, uInt nd, uInt *c, uInt *bl, uInt *bd, inflate
if (r != Z_OK || (*bd == 0 && nl > 257)) if (r != Z_OK || (*bd == 0 && nl > 257))
{ {
if (r == Z_DATA_ERROR) if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed distance tree"; z->msg = "oversubscribed distance tree";
else if (r == Z_BUF_ERROR) { else if (r == Z_BUF_ERROR) {
#ifdef PKZIP_BUG_WORKAROUND #ifdef PKZIP_BUG_WORKAROUND
r = Z_OK; r = Z_OK;
} }
#else #else
z->msg = (char*)"incomplete distance tree"; z->msg = "incomplete distance tree";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
} }
else if (r != Z_MEM_ERROR) else if (r != Z_MEM_ERROR)
{ {
z->msg = (char*)"empty distance tree with lengths"; z->msg = "empty distance tree with lengths";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
} }
ZFREE(z, v); ZFREE(z, v);
@ -3867,7 +3867,7 @@ int inflate_fast(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, inflate_b
} }
else else
{ {
z->msg = (char*)"invalid distance code"; z->msg = "invalid distance code";
UNGRAB UNGRAB
UPDATE UPDATE
return Z_DATA_ERROR; return Z_DATA_ERROR;
@ -3898,7 +3898,7 @@ int inflate_fast(uInt bl, uInt bd, inflate_huft *tl, inflate_huft *td, inflate_b
} }
else else
{ {
z->msg = (char*)"invalid literal/length code"; z->msg = "invalid literal/length code";
UNGRAB UNGRAB
UPDATE UPDATE
return Z_DATA_ERROR; return Z_DATA_ERROR;
@ -4055,7 +4055,7 @@ int inflate_codes(inflate_blocks_statef *s, z_streamp z, int r)
break; break;
} }
c->mode = BADCODE; /* invalid code */ c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid literal/length code"; z->msg = "invalid literal/length code";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
LEAVE LEAVE
case LENEXT: /* i: getting length extra (have base) */ case LENEXT: /* i: getting length extra (have base) */
@ -4087,7 +4087,7 @@ int inflate_codes(inflate_blocks_statef *s, z_streamp z, int r)
break; break;
} }
c->mode = BADCODE; /* invalid code */ c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid distance code"; z->msg = "invalid distance code";
r = Z_DATA_ERROR; r = Z_DATA_ERROR;
LEAVE LEAVE
case DISTEXT: /* i: getting distance extra */ case DISTEXT: /* i: getting distance extra */
@ -4396,14 +4396,14 @@ int inflate(z_streamp z, int f)
if (((z->state->sub.method = iNEXTBYTE) & 0xf) != Z_DEFLATED) if (((z->state->sub.method = iNEXTBYTE) & 0xf) != Z_DEFLATED)
{ {
z->state->mode = imBAD; z->state->mode = imBAD;
z->msg = (char*)"unknown compression method"; z->msg = "unknown compression method";
z->state->sub.marker = 5; /* can't try inflateSync */ z->state->sub.marker = 5; /* can't try inflateSync */
break; break;
} }
if ((z->state->sub.method >> 4) + 8 > z->state->wbits) if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
{ {
z->state->mode = imBAD; z->state->mode = imBAD;
z->msg = (char*)"invalid window size"; z->msg = "invalid window size";
z->state->sub.marker = 5; /* can't try inflateSync */ z->state->sub.marker = 5; /* can't try inflateSync */
break; break;
} }
@ -4414,7 +4414,7 @@ int inflate(z_streamp z, int f)
if (((z->state->sub.method << 8) + b) % 31) if (((z->state->sub.method << 8) + b) % 31)
{ {
z->state->mode = imBAD; z->state->mode = imBAD;
z->msg = (char*)"incorrect header check"; z->msg = "incorrect header check";
z->state->sub.marker = 5; /* can't try inflateSync */ z->state->sub.marker = 5; /* can't try inflateSync */
break; break;
} }
@ -4445,7 +4445,7 @@ int inflate(z_streamp z, int f)
return Z_NEED_DICT; return Z_NEED_DICT;
case imDICT0: case imDICT0:
z->state->mode = imBAD; z->state->mode = imBAD;
z->msg = (char*)"need dictionary"; z->msg = "need dictionary";
z->state->sub.marker = 0; /* can try inflateSync */ z->state->sub.marker = 0; /* can try inflateSync */
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
case imBLOCKS: case imBLOCKS:
@ -4487,7 +4487,7 @@ int inflate(z_streamp z, int f)
if (z->state->sub.check.was != z->state->sub.check.need) if (z->state->sub.check.was != z->state->sub.check.need)
{ {
z->state->mode = imBAD; z->state->mode = imBAD;
z->msg = (char*)"incorrect data check"; z->msg = "incorrect data check";
z->state->sub.marker = 5; /* can't try inflateSync */ z->state->sub.marker = 5; /* can't try inflateSync */
break; break;
} }

View File

@ -92,7 +92,7 @@ typedef struct z_stream_s {
unsigned int avail_out; /* remaining free space at next_out */ unsigned int avail_out; /* remaining free space at next_out */
unsigned long total_out; /* total nb of unsigned chars output so */ unsigned long total_out; /* total nb of unsigned chars output so */
char *msg; /* last error message, NULL if no error */ const char *msg; /* last error message, NULL if no error */
struct internal_state *state; /* not visible by applications */ struct internal_state *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */ alloc_func zalloc; /* used to allocate the internal state */

View File

@ -209,7 +209,7 @@ static void LoadMeshMaterialGroup( FILE *fp, long thisChunkLen, _3DSMeshMaterial
ReadString( fp, mmg.name ); ReadString( fp, mmg.name );
fread( &mmg.numFaces, sizeof( mmg.numFaces ), 1, fp ); fread( &mmg.numFaces, sizeof( mmg.numFaces ), 1, fp );
mmg.pFaces = malloc( sizeof( mmg.pFaces[0] ) * mmg.numFaces ); mmg.pFaces = safe_malloc( sizeof( mmg.pFaces[0] ) * mmg.numFaces );
fread( mmg.pFaces, sizeof( mmg.pFaces[0] ), mmg.numFaces, fp ); fread( mmg.pFaces, sizeof( mmg.pFaces[0] ), mmg.numFaces, fp );
if ( s_verbose ) { if ( s_verbose ) {
@ -256,7 +256,7 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT
fread( &triObj.numFaces, sizeof( triObj.numFaces ), 1, fp ); fread( &triObj.numFaces, sizeof( triObj.numFaces ), 1, fp );
assert( triObj.pFaces == 0 ); assert( triObj.pFaces == 0 );
triObj.pFaces = malloc( sizeof( triObj.pFaces[0] ) * triObj.numFaces ); triObj.pFaces = safe_malloc( sizeof( triObj.pFaces[0] ) * triObj.numFaces );
fread( triObj.pFaces, sizeof( triObj.pFaces[0] ), triObj.numFaces, fp ); fread( triObj.pFaces, sizeof( triObj.pFaces[0] ), triObj.numFaces, fp );
bytesRead += sizeof( triObj.numFaces ) + triObj.numFaces * sizeof( triObj.pFaces[0] ) + 6; bytesRead += sizeof( triObj.numFaces ) + triObj.numFaces * sizeof( triObj.pFaces[0] ) + 6;
@ -271,7 +271,7 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT
break; break;
case _3DS_CHUNK_POINT_ARRAY: case _3DS_CHUNK_POINT_ARRAY:
fread( &triObj.numPoints, sizeof( triObj.numPoints ), 1, fp ); fread( &triObj.numPoints, sizeof( triObj.numPoints ), 1, fp );
triObj.pPoints = malloc( sizeof( triObj.pPoints[0] ) * triObj.numPoints ); triObj.pPoints = safe_malloc( sizeof( triObj.pPoints[0] ) * triObj.numPoints );
fread( triObj.pPoints, sizeof( triObj.pPoints[0] ), triObj.numPoints, fp ); fread( triObj.pPoints, sizeof( triObj.pPoints[0] ), triObj.numPoints, fp );
bytesRead += sizeof( triObj.numPoints ) + triObj.numPoints * sizeof( triObj.pPoints[0] ) + 6; bytesRead += sizeof( triObj.numPoints ) + triObj.numPoints * sizeof( triObj.pPoints[0] ) + 6;
@ -299,7 +299,7 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT
break; break;
case _3DS_CHUNK_TEX_VERTS: case _3DS_CHUNK_TEX_VERTS:
fread( &triObj.numTexVerts, sizeof( triObj.numTexVerts ), 1, fp ); fread( &triObj.numTexVerts, sizeof( triObj.numTexVerts ), 1, fp );
triObj.pTexVerts = malloc( sizeof( triObj.pTexVerts[0] ) * triObj.numTexVerts ); triObj.pTexVerts = safe_malloc( sizeof( triObj.pTexVerts[0] ) * triObj.numTexVerts );
fread( triObj.pTexVerts, sizeof( triObj.pTexVerts[0] ), triObj.numTexVerts, fp ); fread( triObj.pTexVerts, sizeof( triObj.pTexVerts[0] ), triObj.numTexVerts, fp );
bytesRead += sizeof( triObj.numTexVerts ) + sizeof( triObj.pTexVerts[0] ) * triObj.numTexVerts + 6; bytesRead += sizeof( triObj.numTexVerts ) + sizeof( triObj.pTexVerts[0] ) * triObj.numTexVerts + 6;
@ -335,7 +335,7 @@ static void LoadNamedTriObject( FILE *fp, long thisChunkLen, _3DSTriObject_t *pT
assert( pTO->numFaces == meshMaterialGroups[0].numFaces ); assert( pTO->numFaces == meshMaterialGroups[0].numFaces );
} }
pTO->pMeshMaterialGroups = malloc( sizeof( _3DSMeshMaterialGroup_t ) * numMeshMaterialGroups ); pTO->pMeshMaterialGroups = safe_malloc( sizeof( _3DSMeshMaterialGroup_t ) * numMeshMaterialGroups );
memcpy( pTO->pMeshMaterialGroups, meshMaterialGroups, numMeshMaterialGroups * sizeof( meshMaterialGroups[0] ) ); memcpy( pTO->pMeshMaterialGroups, meshMaterialGroups, numMeshMaterialGroups * sizeof( meshMaterialGroups[0] ) );
pTO->numMeshMaterialGroups = numMeshMaterialGroups; pTO->numMeshMaterialGroups = numMeshMaterialGroups;
@ -382,7 +382,7 @@ static void LoadNamedObject( FILE *fp, long thisChunkLen, _3DSNamedObject_t *pNO
} }
strcpy( pNO->name, name ); strcpy( pNO->name, name );
pNO->pTriObjects = malloc( sizeof( _3DSTriObject_t ) * numTriObjects ); pNO->pTriObjects = safe_malloc( sizeof( _3DSTriObject_t ) * numTriObjects );
memcpy( pNO->pTriObjects, triObj, sizeof( triObj[0] ) * numTriObjects ); memcpy( pNO->pTriObjects, triObj, sizeof( triObj[0] ) * numTriObjects );
pNO->numTriObjects = numTriObjects; pNO->numTriObjects = numTriObjects;
@ -441,8 +441,8 @@ static void LoadEditChunk( FILE *fp, long thisChunkLen, _3DSEditChunk_t *pEC ){
pEC->numNamedObjects = numNamedObjects; pEC->numNamedObjects = numNamedObjects;
pEC->pMaterials = malloc( sizeof( _3DSMaterial_t ) * numMaterials ); pEC->pMaterials = safe_malloc( sizeof( _3DSMaterial_t ) * numMaterials );
pEC->pNamedObjects = malloc( sizeof( _3DSNamedObject_t ) * numNamedObjects ); pEC->pNamedObjects = safe_malloc( sizeof( _3DSNamedObject_t ) * numNamedObjects );
memcpy( pEC->pMaterials, mat, numMaterials * sizeof( mat[0] ) ); memcpy( pEC->pMaterials, mat, numMaterials * sizeof( mat[0] ) );
memcpy( pEC->pNamedObjects, namedObjects, numNamedObjects * sizeof( namedObjects[0] ) ); memcpy( pEC->pNamedObjects, namedObjects, numNamedObjects * sizeof( namedObjects[0] ) );
@ -570,8 +570,8 @@ void _3DS_LoadPolysets( const char *filename, polyset_t **ppPSET, int *numpsets,
numPolysets = _3ds.editChunk.numNamedObjects; numPolysets = _3ds.editChunk.numNamedObjects;
// allocate memory // allocate memory
pPSET = calloc( 1, numPolysets * sizeof( polyset_t ) ); pPSET = safe_calloc( numPolysets * sizeof( polyset_t ) );
triangles = ptri = calloc( 1, POLYSET_MAXTRIANGLES * sizeof( triangle_t ) ); triangles = ptri = safe_calloc( POLYSET_MAXTRIANGLES * sizeof( triangle_t ) );
// copy the data over // copy the data over
for ( i = 0; i < numPolysets; i++ ) for ( i = 0; i < numPolysets; i++ )

View File

@ -78,7 +78,7 @@ void Cmd_Grab( void ){
} }
// crop it to the proper size // crop it to the proper size
cropped = malloc( w * h ); cropped = safe_malloc( w * h );
for ( y = 0 ; y < h ; y++ ) for ( y = 0 ; y < h ; y++ )
{ {
memcpy( cropped + y * w, byteimage + ( y + yl ) * byteimagewidth + xl, w ); memcpy( cropped + y * w, byteimage + ( y + yl ) * byteimagewidth + xl, w );
@ -129,7 +129,7 @@ void Cmd_Raw( void ){
} }
// crop it to the proper size // crop it to the proper size
cropped = malloc( w * h ); cropped = safe_malloc( w * h );
for ( y = 0 ; y < h ; y++ ) for ( y = 0 ; y < h ; y++ )
{ {
memcpy( cropped + y * w, byteimage + ( y + yl ) * byteimagewidth + xl, w ); memcpy( cropped + y * w, byteimage + ( y + yl ) * byteimagewidth + xl, w );
@ -235,7 +235,7 @@ void Cmd_Colormap( void ){
levels = 64; levels = 64;
brights = 1; // ignore 255 (transparent) brights = 1; // ignore 255 (transparent)
cropped = malloc( ( levels + 256 ) * 256 ); cropped = safe_malloc( ( levels + 256 ) * 256 );
lump_p = cropped; lump_p = cropped;
// shaded levels // shaded levels
@ -430,7 +430,7 @@ byte AveragePixels( int count ){
*/ */
// 3dstudio environment map suffixes // 3dstudio environment map suffixes
char *suf[6] = {"rt", "ft", "lf", "bk", "up", "dn"}; const char *suf[6] = {"rt", "ft", "lf", "bk", "up", "dn"};
/* /*
================= =================

View File

@ -116,7 +116,7 @@ void MD3_Dump( const char *filename ){
} }
fileSize = Q_filelength( fp ); fileSize = Q_filelength( fp );
_buffer = malloc( fileSize ); _buffer = safe_malloc( fileSize );
fread( _buffer, fileSize, 1, fp ); fread( _buffer, fileSize, 1, fp );
fclose( fp ); fclose( fp );

View File

@ -832,7 +832,7 @@ void Cmd_SpriteBase( void ){
printf( "---------------------\n" ); printf( "---------------------\n" );
g_data.surfData[0].verts[0] = ( float * ) calloc( 1, sizeof( float ) * 6 * 4 ); g_data.surfData[0].verts[0] = safe_calloc( sizeof( float ) * 6 * 4 );
g_data.surfData[0].header.numVerts = 4; g_data.surfData[0].header.numVerts = 4;
@ -1087,7 +1087,7 @@ void GrabFrame( const char *frame ){
if ( g_data.surfData[i].verts[g_data.model.numFrames] ) { if ( g_data.surfData[i].verts[g_data.model.numFrames] ) {
free( g_data.surfData[i].verts[g_data.model.numFrames] ); free( g_data.surfData[i].verts[g_data.model.numFrames] );
} }
frameXyz = g_data.surfData[i].verts[g_data.model.numFrames] = calloc( 1, sizeof( float ) * 6 * g_data.surfData[i].header.numVerts ); frameXyz = g_data.surfData[i].verts[g_data.model.numFrames] = safe_calloc( sizeof( float ) * 6 * g_data.surfData[i].header.numVerts );
frameNormals = frameXyz + 3; frameNormals = frameXyz + 3;
for ( t = 0; t < psets[i].numtriangles; t++ ) for ( t = 0; t < psets[i].numtriangles; t++ )
@ -1773,7 +1773,7 @@ static void BuildAnimationFromOAFs( const char *filename, ObjectAnimationFrame_t
if ( g_data.surfData[i].verts[f] ) { if ( g_data.surfData[i].verts[f] ) {
free( g_data.surfData[i].verts[f] ); free( g_data.surfData[i].verts[f] );
} }
frameXyz = g_data.surfData[i].verts[f] = calloc( 1, sizeof( float ) * 6 * g_data.surfData[i].header.numVerts ); frameXyz = g_data.surfData[i].verts[f] = safe_calloc( sizeof( float ) * 6 * g_data.surfData[i].header.numVerts );
frameNormals = frameXyz + 3; frameNormals = frameXyz + 3;
for ( t = 0; t < pOAF->surfaces[i]->numtriangles; t++ ) for ( t = 0; t < pOAF->surfaces[i]->numtriangles; t++ )

View File

@ -63,7 +63,7 @@ int P3DLoad( const char *filename ){
p3d.len = Q_filelength( fp ); p3d.len = Q_filelength( fp );
p3d.curpos = p3d.buffer = malloc( p3d.len ); p3d.curpos = p3d.buffer = safe_malloc( p3d.len );
if ( fread( p3d.buffer, p3d.len, 1, fp ) != 1 ) { if ( fread( p3d.buffer, p3d.len, 1, fp ) != 1 ) {
fclose( fp ); fclose( fp );

View File

@ -40,7 +40,7 @@ polyset_t *Polyset_SplitSets( polyset_t *psets, int numpolysets, int *pNumNewPol
printf( "Warning: creating %d polysets from input of %d polysets\n", numNewPolysets, numpolysets ); printf( "Warning: creating %d polysets from input of %d polysets\n", numNewPolysets, numpolysets );
newpsets = calloc( sizeof( polyset_t ) * numNewPolysets, 1 ); newpsets = safe_calloc( sizeof( polyset_t ) * numNewPolysets );
for ( np = 0, op = 0; op < numpolysets; op++ ) for ( np = 0, op = 0; op < numpolysets; op++ )
{ {
@ -129,9 +129,9 @@ polyset_t *Polyset_CollapseSets( polyset_t *psets, int numpolysets ){
sumtriangles += oldpsets[p].numtriangles; sumtriangles += oldpsets[p].numtriangles;
} }
psets = calloc( 1, sizeof( polyset_t ) ); psets = safe_calloc( sizeof( polyset_t ) );
psets[0].numtriangles = sumtriangles; psets[0].numtriangles = sumtriangles;
psets[0].triangles = malloc( MD3_MAX_TRIANGLES * sizeof( triangle_t ) ); psets[0].triangles = safe_malloc( MD3_MAX_TRIANGLES * sizeof( triangle_t ) );
// each call to "LoadPolysets" only allocates a single large chunk of // each call to "LoadPolysets" only allocates a single large chunk of
// triangle memory that is utilized by all the polysets loaded by // triangle memory that is utilized by all the polysets loaded by

View File

@ -106,14 +106,14 @@ void FindShaderFiles( char *filename ){
char linebuffer[1024]; char linebuffer[1024];
int len, i; int len, i;
char *buf; char *buf;
char *diffuseExtensions[] = const char *diffuseExtensions[] =
{ {
".TGA", ".TGA",
".WAL", ".WAL",
".PCX", ".PCX",
0 0
}; };
char *otherExtensions[] = const char *otherExtensions[] =
{ {
".specular.TGA", ".specular.TGA",
".blend.TGA", ".blend.TGA",

View File

@ -86,7 +86,7 @@ int GetLittleLong( void ){
return val; return val;
} }
void FindNextChunk( char *name ){ void FindNextChunk( const char *name ){
while ( 1 ) while ( 1 )
{ {
data_p = last_chunk; data_p = last_chunk;
@ -112,7 +112,7 @@ void FindNextChunk( char *name ){
} }
} }
void FindChunk( char *name ){ void FindChunk( const char *name ){
last_chunk = iff_data; last_chunk = iff_data;
FindNextChunk( name ); FindNextChunk( name );
} }
@ -128,7 +128,7 @@ void DumpChunks( void ){
memcpy( str, data_p, 4 ); memcpy( str, data_p, 4 );
data_p += 4; data_p += 4;
iff_chunk_len = GetLittleLong(); iff_chunk_len = GetLittleLong();
printf( "0x%x : %s (%d)\n", (int)( data_p - 4 ), str, iff_chunk_len ); printf( "0x%p : %s (%d)\n", data_p - 4, str, iff_chunk_len );
data_p += ( iff_chunk_len + 1 ) & ~1; data_p += ( iff_chunk_len + 1 ) & ~1;
} while ( data_p < iff_end ); } while ( data_p < iff_end );
} }
@ -248,7 +248,7 @@ void LoadSoundtrack( void ){
return; return;
} }
len = Q_filelength( f ); len = Q_filelength( f );
s_soundtrack = malloc( len ); s_soundtrack = safe_malloc( len );
fread( s_soundtrack, 1, len, f ); fread( s_soundtrack, 1, len, f );
fclose( f ); fclose( f );
@ -945,8 +945,8 @@ void Cmd_Video( void ){
GetToken( false ); GetToken( false );
s_resample_height = atoi( token ); s_resample_height = atoi( token );
resampled = malloc( sizeof( unsigned char ) * 4 * s_resample_width * s_resample_height ); resampled = safe_malloc( sizeof( unsigned char ) * 4 * s_resample_width * s_resample_height );
compressed = malloc( sizeof( long ) * 2 * ( s_resample_width / 4 ) * ( s_resample_height / 4 ) ); compressed = safe_malloc( sizeof( long ) * 2 * ( s_resample_width / 4 ) * ( s_resample_height / 4 ) );
printf( "Resample width: %d\n", s_resample_width ); printf( "Resample width: %d\n", s_resample_width );
printf( "Resample height: %d\n", s_resample_height ); printf( "Resample height: %d\n", s_resample_height );
@ -1064,7 +1064,7 @@ void Cmd_Video( void ){
unsigned char *uncompressed; unsigned char *uncompressed;
char buffer[1000]; char buffer[1000];
uncompressed = malloc( sizeof( unsigned char ) * 4 * s_resample_width * s_resample_height ); uncompressed = safe_malloc( sizeof( unsigned char ) * 4 * s_resample_width * s_resample_height );
BTCDecompressFrame( compressed, uncompressed ); BTCDecompressFrame( compressed, uncompressed );
for ( y = 0; y < s_resample_height / 2; y++ ) for ( y = 0; y < s_resample_height / 2; y++ )

View File

@ -41,9 +41,8 @@ StrList;
static inline StrList* StrList_allocate( size_t strNum ){ static inline StrList* StrList_allocate( size_t strNum ){
StrList* ret = safe_calloc( offsetof( StrList, s[strNum] ) ); StrList* ret = safe_calloc( offsetof( StrList, s[strNum] ) );
memcpy( ret, ret->n = 0;
&( StrList const ){ .n = 0, .max = strNum }, ret->max = strNum;
sizeof( StrList ) );
return ret; return ret;
} }
@ -196,9 +195,8 @@ StrBuf;
static inline StrBuf* StrBuf_allocate( size_t strLen ){ static inline StrBuf* StrBuf_allocate( size_t strLen ){
StrBuf* ret = safe_calloc( offsetof( StrBuf, s[strLen] ) ); StrBuf* ret = safe_calloc( offsetof( StrBuf, s[strLen] ) );
memcpy( ret, ret->strlen = 0;
&( StrBuf const ){ .strlen = 0, .max = strLen }, ret->max = strLen;
sizeof( StrBuf ) );
return ret; return ret;
} }

View File

@ -611,7 +611,7 @@ vec_t BrushVolume( brush_t *brush ){
writes a map with the split bsp brushes writes a map with the split bsp brushes
*/ */
void WriteBSPBrushMap( char *name, brush_t *list ){ void WriteBSPBrushMap( const char *name, brush_t *list ){
FILE *f; FILE *f;
side_t *s; side_t *s;
int i; int i;

View File

@ -358,7 +358,7 @@ void ProcessWorldModel( void ){
xmlAddChild( leaknode, polyline ); xmlAddChild( leaknode, polyline );
level[0] = (int) '0' + SYS_ERR; level[0] = (int) '0' + SYS_ERR;
level[1] = 0; level[1] = 0;
xmlSetProp( leaknode, (xmlChar*)"level", (const xmlChar*)level ); xmlSetProp( leaknode, (const xmlChar*)"level", (const xmlChar*)level );
xml_SendNode( leaknode ); xml_SendNode( leaknode );
if ( leaktest ) { if ( leaktest ) {
Sys_FPrintf( SYS_WRN, "--- MAP LEAKED, ABORTING LEAKTEST ---\n" ); Sys_FPrintf( SYS_WRN, "--- MAP LEAKED, ABORTING LEAKTEST ---\n" );

View File

@ -73,7 +73,7 @@ void IncDrawVerts(){
numBSPDrawVertsBuffer *= 3; // multiply by 1.5 numBSPDrawVertsBuffer *= 3; // multiply by 1.5
numBSPDrawVertsBuffer /= 2; numBSPDrawVertsBuffer /= 2;
newBspDrawVerts = realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer ); newBspDrawVerts = void_ptr( realloc( bspDrawVerts, sizeof( bspDrawVert_t ) * numBSPDrawVertsBuffer ) );
if ( !newBspDrawVerts ) { if ( !newBspDrawVerts ) {
free (bspDrawVerts); free (bspDrawVerts);
@ -276,7 +276,7 @@ int GetLumpElements( bspHeader_t *header, int lump, int size ){
returns a pointer to the specified lump returns a pointer to the specified lump
*/ */
void *GetLump( bspHeader_t *header, int lump ){ void_ptr GetLump( bspHeader_t *header, int lump ){
return (void*)( (byte*) header + header->lumps[ lump ].offset ); return (void*)( (byte*) header + header->lumps[ lump ].offset );
} }
@ -871,7 +871,7 @@ void GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec ){
} }
} }
bool entity_read_bool( bool *bool_value, const entity_t *entity, ... ){ bool entity_read_keyvalue( bool *bool_value, const entity_t *entity, ... ){
va_list argptr; va_list argptr;
va_start( argptr, entity ); va_start( argptr, entity );
const char* key; const char* key;
@ -886,7 +886,7 @@ bool entity_read_bool( bool *bool_value, const entity_t *entity, ... ){
va_end( argptr ); va_end( argptr );
return false; return false;
} }
bool entity_read_int( int *int_value, const entity_t *entity, ... ){ bool entity_read_keyvalue( int *int_value, const entity_t *entity, ... ){
va_list argptr; va_list argptr;
va_start( argptr, entity ); va_start( argptr, entity );
const char* key; const char* key;
@ -901,7 +901,7 @@ bool entity_read_int( int *int_value, const entity_t *entity, ... ){
va_end( argptr ); va_end( argptr );
return false; return false;
} }
bool entity_read_float( float *float_value, const entity_t *entity, ... ){ bool entity_read_keyvalue( float *float_value, const entity_t *entity, ... ){
va_list argptr; va_list argptr;
va_start( argptr, entity ); va_start( argptr, entity );
const char* key; const char* key;
@ -916,7 +916,7 @@ bool entity_read_float( float *float_value, const entity_t *entity, ... ){
va_end( argptr ); va_end( argptr );
return false; return false;
} }
bool entity_read_vector3( float (*vector3_value)[3], const entity_t *entity, ... ){ bool entity_read_keyvalue( float (*vector3_value)[3], const entity_t *entity, ... ){
va_list argptr; va_list argptr;
va_start( argptr, entity ); va_start( argptr, entity );
const char* key; const char* key;
@ -936,7 +936,7 @@ bool entity_read_vector3( float (*vector3_value)[3], const entity_t *entity, ...
va_end( argptr ); va_end( argptr );
return false; return false;
} }
bool entity_read_string( char (*string_value)[], const entity_t *entity, ... ){ bool entity_read_keyvalue( char (*string_value)[1024], const entity_t *entity, ... ){
va_list argptr; va_list argptr;
va_start( argptr, entity ); va_start( argptr, entity );
const char* key; const char* key;
@ -951,7 +951,7 @@ bool entity_read_string( char (*string_value)[], const entity_t *entity, ... ){
va_end( argptr ); va_end( argptr );
return false; return false;
} }
bool entity_read_string_ptr( const char **string_ptr_value, const entity_t *entity, ... ){ bool entity_read_keyvalue( const char **string_ptr_value, const entity_t *entity, ... ){
va_list argptr; va_list argptr;
va_start( argptr, entity ); va_start( argptr, entity );
const char* key; const char* key;

View File

@ -452,7 +452,7 @@ void LoadIBSPFile( const char *filename ){
SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) ); SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) );
/* make sure it matches the format we're trying to load */ /* make sure it matches the format we're trying to load */
if ( !force && *( (int*) header->ident ) != *( (int*) game->bspIdent ) ) { if ( !force && *( (int*) header->ident ) != *( (const int*) game->bspIdent ) ) {
Error( "%s is not a %s file", filename, game->bspIdent ); Error( "%s is not a %s file", filename, game->bspIdent );
} }
if ( !force && header->version != game->bspVersion ) { if ( !force && header->version != game->bspVersion ) {
@ -524,7 +524,7 @@ void PartialLoadIBSPFile( const char *filename ){
SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) ); SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) );
/* make sure it matches the format we're trying to load */ /* make sure it matches the format we're trying to load */
if ( !force && *( (int*) header->ident ) != *( (int*) game->bspIdent ) ) { if ( !force && *( (int*) header->ident ) != *( (const int*) game->bspIdent ) ) {
Error( "%s is not a %s file", filename, game->bspIdent ); Error( "%s is not a %s file", filename, game->bspIdent );
} }
if ( !force && header->version != game->bspVersion ) { if ( !force && header->version != game->bspVersion ) {
@ -564,7 +564,7 @@ void WriteIBSPFile( const char *filename ){
//% Swapfile(); //% Swapfile();
/* set up header */ /* set up header */
*( (int*) (bspHeader_t*) header->ident ) = *( (int*) game->bspIdent ); *( (int*) (bspHeader_t*) header->ident ) = *( (const int*) game->bspIdent );
header->version = LittleLong( game->bspVersion ); header->version = LittleLong( game->bspVersion );
/* write initial header */ /* write initial header */

View File

@ -221,7 +221,7 @@ void LoadRBSPFile( const char *filename ){
SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) ); SwapBlock( (int*) ( (byte*) header + sizeof( int ) ), sizeof( *header ) - sizeof( int ) );
/* make sure it matches the format we're trying to load */ /* make sure it matches the format we're trying to load */
if ( !force && *( (int*) header->ident ) != *( (int*) game->bspIdent ) ) { if ( !force && *( (int*) header->ident ) != *( (const int*) game->bspIdent ) ) {
Error( "%s is not a %s file", filename, game->bspIdent ); Error( "%s is not a %s file", filename, game->bspIdent );
} }
if ( !force && header->version != game->bspVersion ) { if ( !force && header->version != game->bspVersion ) {
@ -295,7 +295,7 @@ void WriteRBSPFile( const char *filename ){
//% Swapfile(); //% Swapfile();
/* set up header */ /* set up header */
*( (int*) (bspHeader_t*) header->ident ) = *( (int*) game->bspIdent ); *( (int*) (bspHeader_t*) header->ident ) = *( (const int*) game->bspIdent );
header->version = LittleLong( game->bspVersion ); header->version = LittleLong( game->bspVersion );
/* write initial header */ /* write initial header */

View File

@ -47,8 +47,9 @@ int FixAAS( int argc, char **argv ){
int length, checksum; int length, checksum;
void *buffer; void *buffer;
FILE *file; FILE *file;
char aas[ 1024 ], **ext; char aas[ 1024 ];
char *exts[] = const char **ext;
const char *exts[] =
{ {
".aas", ".aas",
"_b0.aas", "_b0.aas",
@ -123,7 +124,7 @@ abspHeader_t;
typedef struct abspLumpTest_s typedef struct abspLumpTest_s
{ {
int radix, minCount; int radix, minCount;
char *name; const char *name;
} }
abspLumpTest_t; abspLumpTest_t;

View File

@ -164,7 +164,7 @@ exwinding:
static void ConvertOriginBrush( FILE *f, int num, vec3_t origin, bool brushPrimitives ){ static void ConvertOriginBrush( FILE *f, int num, vec3_t origin, bool brushPrimitives ){
int originSize = 256; int originSize = 256;
char pattern[6][7][3] = { char pattern[6][7][4] = {
{ "+++", "+-+", "-++", "- ", " + ", " - ", "- " }, { "+++", "+-+", "-++", "- ", " + ", " - ", "- " },
{ "+++", "-++", "++-", "- ", " +", "+ ", " +" }, { "+++", "-++", "++-", "- ", " +", "+ ", " +" },
{ "+++", "++-", "+-+", " - ", " +", " - ", " +" }, { "+++", "++-", "+-+", " - ", " +", " - ", " +" },
@ -375,7 +375,7 @@ static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, vec3_t origin, bo
bspBrushSide_t *side; bspBrushSide_t *side;
side_t *buildSide; side_t *buildSide;
bspShader_t *shader; bspShader_t *shader;
char *texture; const char *texture;
plane_t *buildPlane; plane_t *buildPlane;
vec3_t pts[ 3 ]; vec3_t pts[ 3 ];
bspDrawVert_t *vert[3]; bspDrawVert_t *vert[3];

View File

@ -42,12 +42,12 @@ struct HelpOption
void HelpOptions(const char* group_name, int indentation, int width, struct HelpOption* options, int count) void HelpOptions(const char* group_name, int indentation, int width, struct HelpOption* options, int count)
{ {
indentation *= 2; indentation *= 2;
char* indent = malloc(indentation+1); char* indent = safe_malloc(indentation+1);
memset(indent, ' ', indentation); memset(indent, ' ', indentation);
indent[indentation] = 0; indent[indentation] = 0;
printf("%s%s:\n", indent, group_name); printf("%s%s:\n", indent, group_name);
indentation += 2; indentation += 2;
indent = realloc(indent, indentation+1); indent = void_ptr( realloc(indent, indentation+1) );
memset(indent, ' ', indentation); memset(indent, ' ', indentation);
indent[indentation] = 0; indent[indentation] = 0;

View File

@ -282,7 +282,7 @@ static int AddItemToTraceNode( traceNode_t *node, int num ){
if ( node->maxItems <= 0 ) { if ( node->maxItems <= 0 ) {
node->maxItems = GROW_NODE_ITEMS; node->maxItems = GROW_NODE_ITEMS;
} }
node->items = realloc( node->items, node->maxItems * sizeof( *node->items ) ); node->items = void_ptr( realloc( node->items, node->maxItems * sizeof( *node->items ) ) );
if ( !node->items ) { if ( !node->items ) {
Error( "node->items out of memory" ); Error( "node->items out of memory" );
} }

View File

@ -223,7 +223,7 @@ int ImportLightmapsMain( int argc, char **argv ){
sprintf( filename, "%s/lightmap_%04d.tga", dirname, i ); sprintf( filename, "%s/lightmap_%04d.tga", dirname, i );
Sys_Printf( "Loading %s\n", filename ); Sys_Printf( "Loading %s\n", filename );
buffer = NULL; buffer = NULL;
len = vfsLoadFile( filename, (void*) &buffer, -1 ); len = vfsLoadFile( filename, (void**) &buffer, -1 );
if ( len < 0 ) { if ( len < 0 ) {
Sys_Warning( "Unable to load image %s\n", filename ); Sys_Warning( "Unable to load image %s\n", filename );
continue; continue;

View File

@ -146,7 +146,7 @@ int main( int argc, char **argv ){
/* init model library */ /* init model library */
PicoInit(); PicoInit();
PicoSetMallocFunc( safe_malloc ); PicoSetMallocFunc( malloc );
PicoSetFreeFunc( free ); PicoSetFreeFunc( free );
PicoSetPrintFunc( PicoPrintFunc ); PicoSetPrintFunc( PicoPrintFunc );
PicoSetLoadFileFunc( PicoLoadFileFunc ); PicoSetLoadFileFunc( PicoLoadFileFunc );

View File

@ -1628,7 +1628,8 @@ void LoadEntityIndexMap( entity_t *e ){
im->pixels = pixels; im->pixels = pixels;
/* get height offsets */ /* get height offsets */
char offset[ 4096 ]; // char offset[ 4096 ];
char offset[ 1024 ];
if( ENT_READKV( &offset, mapEnt, "_offsets", "offsets" ) ){ if( ENT_READKV( &offset, mapEnt, "_offsets", "offsets" ) ){
/* value is a space-separated set of numbers */ /* value is a space-separated set of numbers */
char *search = offset; char *search = offset;

View File

@ -522,7 +522,7 @@ int MiniMapBSPMain( int argc, char **argv ){
i++; i++;
Sys_Printf( "Samples set to %i\n", minimap.samples ); Sys_Printf( "Samples set to %i\n", minimap.samples );
free( minimap.sample_offsets ); free( minimap.sample_offsets );
minimap.sample_offsets = malloc( 2 * sizeof( *minimap.sample_offsets ) * minimap.samples ); minimap.sample_offsets = safe_malloc( 2 * sizeof( *minimap.sample_offsets ) * minimap.samples );
MiniMapMakeSampleOffsets(); MiniMapMakeSampleOffsets();
} }
else if ( strEqual( argv[ i ], "-random" ) ) { else if ( strEqual( argv[ i ], "-random" ) ) {

View File

@ -43,7 +43,7 @@
#define MAX_GAME_PATHS 10 #define MAX_GAME_PATHS 10
#define MAX_PAK_PATHS 200 #define MAX_PAK_PATHS 200
char *homePath; const char *homePath;
char installPath[ MAX_OS_PATH ]; char installPath[ MAX_OS_PATH ];
int numBasePaths; int numBasePaths;
@ -52,7 +52,7 @@ int numGamePaths;
char *gamePaths[ MAX_GAME_PATHS ]; char *gamePaths[ MAX_GAME_PATHS ];
int numPakPaths; int numPakPaths;
char *pakPaths[ MAX_PAK_PATHS ]; char *pakPaths[ MAX_PAK_PATHS ];
char *homeBasePath = NULL; const char *homeBasePath = NULL;
/* /*
@ -263,7 +263,7 @@ void AddBasePath( char *path ){
adds a base path to the beginning of the list, prefixed by ~/ adds a base path to the beginning of the list, prefixed by ~/
*/ */
void AddHomeBasePath( char *path ){ void AddHomeBasePath( const char *path ){
int i; int i;
char temp[ MAX_OS_PATH ]; char temp[ MAX_OS_PATH ];
@ -313,7 +313,7 @@ void AddHomeBasePath( char *path ){
adds a game path to the list adds a game path to the list
*/ */
void AddGamePath( char *path ){ void AddGamePath( const char *path ){
int i; int i;
/* dummy check */ /* dummy check */

View File

@ -524,7 +524,7 @@ typedef float tcMod_t[ 3 ][ 3 ];
/* ydnar: for multiple game support */ /* ydnar: for multiple game support */
typedef struct surfaceParm_s typedef struct surfaceParm_s
{ {
char *name; const char *name;
int contentFlags, contentFlagsClear; int contentFlags, contentFlagsClear;
int surfaceFlags, surfaceFlagsClear; int surfaceFlags, surfaceFlagsClear;
int compileFlags, compileFlagsClear; int compileFlags, compileFlagsClear;
@ -541,16 +541,16 @@ miniMapMode_t;
typedef struct game_s typedef struct game_s
{ {
char *arg; /* -game matches this */ const char *arg; /* -game matches this */
char *gamePath; /* main game data dir */ const char *gamePath; /* main game data dir */
char *homeBasePath; /* home sub-dir on unix */ const char *homeBasePath; /* home sub-dir on unix */
char *magic; /* magic word for figuring out base path */ const char *magic; /* magic word for figuring out base path */
char *shaderPath; /* shader directory */ const char *shaderPath; /* shader directory */
int maxLMSurfaceVerts; /* default maximum meta surface verts */ int maxLMSurfaceVerts; /* default maximum meta surface verts */
int maxSurfaceVerts; /* default maximum surface verts */ int maxSurfaceVerts; /* default maximum surface verts */
int maxSurfaceIndexes; /* default maximum surface indexes (tris * 3) */ int maxSurfaceIndexes; /* default maximum surface indexes (tris * 3) */
bool emitFlares; /* when true, emit flare surfaces */ bool emitFlares; /* when true, emit flare surfaces */
char *flareShader; /* default flare shader (MUST BE SET) */ const char *flareShader; /* default flare shader (MUST BE SET) */
bool wolfLight; /* when true, lights work like wolf q3map */ bool wolfLight; /* when true, lights work like wolf q3map */
int lightmapSize; /* bsp lightmap width/height */ int lightmapSize; /* bsp lightmap width/height */
float lightmapGamma; /* default lightmap gamma */ float lightmapGamma; /* default lightmap gamma */
@ -573,8 +573,8 @@ typedef struct game_s
float miniMapBorder; /* minimap border amount */ float miniMapBorder; /* minimap border amount */
bool miniMapKeepAspect; /* minimap keep aspect ratio by letterboxing */ bool miniMapKeepAspect; /* minimap keep aspect ratio by letterboxing */
miniMapMode_t miniMapMode; /* minimap mode */ miniMapMode_t miniMapMode; /* minimap mode */
char *miniMapNameFormat; /* minimap name format */ const char *miniMapNameFormat; /* minimap name format */
char *bspIdent; /* 4-letter bsp file prefix */ const char *bspIdent; /* 4-letter bsp file prefix */
int bspVersion; /* bsp version to use */ int bspVersion; /* bsp version to use */
bool lumpSwap; /* cod-style len/ofs order */ bool lumpSwap; /* cod-style len/ofs order */
bspFunc load, write; /* load/write function pointers */ bspFunc load, write; /* load/write function pointers */
@ -700,7 +700,7 @@ typedef struct shaderInfo_s
int compileFlags; int compileFlags;
float value; /* light value */ float value; /* light value */
char *flareShader; /* for light flares */ const char *flareShader; /* for light flares */
char *damageShader; /* ydnar: sof2 damage shader name */ char *damageShader; /* ydnar: sof2 damage shader name */
char *backShader; /* for surfaces that generate different front and back passes */ char *backShader; /* for surfaces that generate different front and back passes */
char *cloneShader; /* ydnar: for cloning of a surface */ char *cloneShader; /* ydnar: for cloning of a surface */
@ -997,7 +997,7 @@ surfaceType_t;
#ifndef MAIN_C #ifndef MAIN_C
extern extern
#endif #endif
char *surfaceTypes[ NUM_SURFACE_TYPES ] const char *surfaceTypes[ NUM_SURFACE_TYPES ]
#ifndef MAIN_C #ifndef MAIN_C
; ;
#else #else
@ -1556,7 +1556,7 @@ bool BoundBrush( brush_t *brush );
bool CreateBrushWindings( brush_t *brush ); bool CreateBrushWindings( brush_t *brush );
brush_t *BrushFromBounds( vec3_t mins, vec3_t maxs ); brush_t *BrushFromBounds( vec3_t mins, vec3_t maxs );
vec_t BrushVolume( brush_t *brush ); vec_t BrushVolume( brush_t *brush );
void WriteBSPBrushMap( char *name, brush_t *list ); void WriteBSPBrushMap( const char *name, brush_t *list );
void FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree ); void FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
void FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree ); void FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
@ -1586,8 +1586,6 @@ mesh_t *RemoveLinearMeshColumnsRows( mesh_t *in );
void MakeMeshNormals( mesh_t in ); void MakeMeshNormals( mesh_t in );
void PutMeshOnCurve( mesh_t in ); void PutMeshOnCurve( mesh_t in );
void MakeNormalVectors( vec3_t forward, vec3_t right, vec3_t up );
/* map.c */ /* map.c */
void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups ); void LoadMapFile( char *filename, bool onlyLights, bool noCollapseGroups );
@ -1864,11 +1862,11 @@ void TCModTranslate( tcMod_t mod, float s, float t );
void TCModScale( tcMod_t mod, float s, float t ); void TCModScale( tcMod_t mod, float s, float t );
void TCModRotate( tcMod_t mod, float euler ); void TCModRotate( tcMod_t mod, float euler );
bool ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags ); bool ApplySurfaceParm( const char *name, int *contentFlags, int *surfaceFlags, int *compileFlags );
void BeginMapShaderFile( const char *mapFile ); void BeginMapShaderFile( const char *mapFile );
void WriteMapShaderFile( void ); void WriteMapShaderFile( void );
shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ); shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace );
void EmitVertexRemapShader( char *from, char *to ); void EmitVertexRemapShader( char *from, char *to );
void LoadShaderInfo( void ); void LoadShaderInfo( void );
@ -1887,7 +1885,7 @@ void BSPFilesCleanup();
void SwapBlock( int *block, int size ); void SwapBlock( int *block, int size );
int GetLumpElements( bspHeader_t *header, int lump, int size ); int GetLumpElements( bspHeader_t *header, int lump, int size );
void *GetLump( bspHeader_t *header, int lump ); void_ptr GetLump( bspHeader_t *header, int lump );
int CopyLump( bspHeader_t *header, int lump, void *dest, int size ); int CopyLump( bspHeader_t *header, int lump, void *dest, int size );
int CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable ); int CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable );
void AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length ); void AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length );
@ -1913,20 +1911,13 @@ void GetVectorForKey( const entity_t *ent, const char *ke
/* entity: read key value generic macro /* entity: read key value generic macro
returns true on successful read returns true on successful read
returns false and does not modify value otherwise */ returns false and does not modify value otherwise */
bool entity_read_bool( bool *bool_value, const entity_t *entity, ... ); bool entity_read_keyvalue( bool *bool_value, const entity_t *entity, ... );
bool entity_read_int( int *int_value, const entity_t *entity, ... ); bool entity_read_keyvalue( int *int_value, const entity_t *entity, ... );
bool entity_read_float( float *float_value, const entity_t *entity, ... ); // warning: float[3] may be passed here erroneously, if not written as &float[3] bool entity_read_keyvalue( float *float_value, const entity_t *entity, ... ); // warning: float[3] may be passed here erroneously, if not written as &float[3]
bool entity_read_vector3( float (*vector3_value)[3], const entity_t *entity, ... ); bool entity_read_keyvalue( float (*vector3_value)[3], const entity_t *entity, ... );
bool entity_read_string( char (*string_value)[], const entity_t *entity, ... ); // explicit pointer to array to avoid erroneous mix of char* and char** bool entity_read_keyvalue( char (*string_value)[1024], const entity_t *entity, ... ); // explicit pointer to array to avoid erroneous mix of char* and char**
bool entity_read_string_ptr( const char **string_ptr_value, const entity_t *entity, ... ); bool entity_read_keyvalue( const char **string_ptr_value, const entity_t *entity, ... );
#define ENT_READKV( value_ptr, entity, keys... ) _Generic( ( value_ptr ), \ #define ENT_READKV( value_ptr, entity, keys... ) entity_read_keyvalue( value_ptr, entity, keys, NULL )
bool*: entity_read_bool, \
int*: entity_read_int, \
float*: entity_read_float, \
float (*)[3]: entity_read_vector3,\
char (*)[]: entity_read_string, \
const char**: entity_read_string_ptr\
)( value_ptr, entity, keys, NULL )
const char *ent_classname( const entity_t *entity ); const char *ent_classname( const entity_t *entity );
bool ent_class_is( const entity_t *entity, const char *classname ); bool ent_class_is( const entity_t *entity, const char *classname );
@ -2132,9 +2123,9 @@ Q_EXTERN char name[ 1024 ];
Q_EXTERN char source[ 1024 ]; Q_EXTERN char source[ 1024 ];
Q_EXTERN char outbase[ 32 ]; Q_EXTERN char outbase[ 32 ];
Q_EXTERN int sampleSize; /* lightmap sample size in units */ Q_EXTERN int sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE ); /* lightmap sample size in units */
Q_EXTERN int minSampleSize; /* minimum sample size to use at all */ Q_EXTERN int minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE ); /* minimum sample size to use at all */
Q_EXTERN int sampleScale; /* vortex: lightmap sample scale (ie quality)*/ Q_EXTERN int sampleScale; /* vortex: lightmap sample scale (ie quality)*/
Q_EXTERN int mapEntityNum Q_ASSIGN( 0 ); Q_EXTERN int mapEntityNum Q_ASSIGN( 0 );
@ -2258,8 +2249,8 @@ Q_EXTERN bool loMem Q_ASSIGN( false );
Q_EXTERN bool noStyles Q_ASSIGN( false ); Q_EXTERN bool noStyles Q_ASSIGN( false );
Q_EXTERN bool keepLights Q_ASSIGN( false ); Q_EXTERN bool keepLights Q_ASSIGN( false );
Q_EXTERN int sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE ); //Q_EXTERN int sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE );
Q_EXTERN int minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE ); //Q_EXTERN int minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE );
Q_EXTERN float noVertexLighting Q_ASSIGN( 0.0f ); Q_EXTERN float noVertexLighting Q_ASSIGN( 0.0f );
Q_EXTERN bool nolm Q_ASSIGN( false ); Q_EXTERN bool nolm Q_ASSIGN( false );
Q_EXTERN bool noGridLighting Q_ASSIGN( false ); Q_EXTERN bool noGridLighting Q_ASSIGN( false );
@ -2589,7 +2580,7 @@ Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ];
{ \ { \
Error( # ptr " over 2 GB" ); \ Error( # ptr " over 2 GB" ); \
} \ } \
ptr = realloc( ptr, sizeof( *ptr ) * allocated ); \ ptr = void_ptr( realloc( ptr, sizeof( *ptr ) * allocated ) ); \
if ( !ptr ) { \ if ( !ptr ) { \
Error( # ptr " out of memory" ); } \ Error( # ptr " out of memory" ); } \
} \ } \
@ -2604,7 +2595,7 @@ Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ];
if ( used >= allocated ) \ if ( used >= allocated ) \
{ \ { \
allocated += add; \ allocated += add; \
ptr = realloc( ptr, sizeof( *ptr ) * allocated ); \ ptr = void_ptr( realloc( ptr, sizeof( *ptr ) * allocated ) ); \
if ( !ptr ) { \ if ( !ptr ) { \
Error( # ptr " out of memory" ); } \ Error( # ptr " out of memory" ); } \
} \ } \

View File

@ -237,7 +237,7 @@ void TCModRotate( tcMod_t mod, float euler ){
applies a named surfaceparm to the supplied flags applies a named surfaceparm to the supplied flags
*/ */
bool ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags ){ bool ApplySurfaceParm( const char *name, int *contentFlags, int *surfaceFlags, int *compileFlags ){
int i, fake; int i, fake;
surfaceParm_t *sp; surfaceParm_t *sp;
@ -415,7 +415,7 @@ void WriteMapShaderFile( void ){
sets up a custom map shader sets up a custom map shader
*/ */
shaderInfo_t *CustomShader( shaderInfo_t *si, char *find, char *replace ){ shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace ){
shaderInfo_t *csi; shaderInfo_t *csi;
char shader[ MAX_QPATH ]; char shader[ MAX_QPATH ];
char *s; char *s;
@ -1719,11 +1719,10 @@ static void ParseShaderFile( const char *filename ){
striEqual( token, "q3map_rgbGen" ) || striEqual( token, "q3map_rgbMod" ) || striEqual( token, "q3map_rgbGen" ) || striEqual( token, "q3map_rgbMod" ) ||
striEqual( token, "q3map_alphaGen" ) || striEqual( token, "q3map_alphaMod" ) ) { striEqual( token, "q3map_alphaGen" ) || striEqual( token, "q3map_alphaMod" ) ) {
colorMod_t *cm, *cm2; colorMod_t *cm, *cm2;
int alpha;
/* alphamods are colormod + 1 */ /* alphamods are colormod + 1 */
alpha = ( striEqual( token, "q3map_alphaGen" ) || striEqual( token, "q3map_alphaMod" ) ) ? 1 : 0; const bool alpha = striEqual( token, "q3map_alphaGen" ) || striEqual( token, "q3map_alphaMod" );
/* allocate new colormod */ /* allocate new colormod */
cm = safe_calloc( sizeof( *cm ) ); cm = safe_calloc( sizeof( *cm ) );
@ -1779,25 +1778,25 @@ static void ParseShaderFile( const char *filename ){
/* dotProduct ( X Y Z ) */ /* dotProduct ( X Y Z ) */
else if ( striEqual( token, "dotProduct" ) ) { else if ( striEqual( token, "dotProduct" ) ) {
cm->type = CM_COLOR_DOT_PRODUCT + alpha; cm->type = alpha? CM_ALPHA_DOT_PRODUCT : CM_COLOR_DOT_PRODUCT;
Parse1DMatrixAppend( shaderText, 3, cm->data ); Parse1DMatrixAppend( shaderText, 3, cm->data );
} }
/* dotProductScale ( X Y Z MIN MAX ) */ /* dotProductScale ( X Y Z MIN MAX ) */
else if ( striEqual( token, "dotProductScale" ) ) { else if ( striEqual( token, "dotProductScale" ) ) {
cm->type = CM_COLOR_DOT_PRODUCT_SCALE + alpha; cm->type = alpha? CM_ALPHA_DOT_PRODUCT_SCALE : CM_COLOR_DOT_PRODUCT_SCALE;
Parse1DMatrixAppend( shaderText, 5, cm->data ); Parse1DMatrixAppend( shaderText, 5, cm->data );
} }
/* dotProduct2 ( X Y Z ) */ /* dotProduct2 ( X Y Z ) */
else if ( striEqual( token, "dotProduct2" ) ) { else if ( striEqual( token, "dotProduct2" ) ) {
cm->type = CM_COLOR_DOT_PRODUCT_2 + alpha; cm->type = alpha? CM_ALPHA_DOT_PRODUCT_2 : CM_COLOR_DOT_PRODUCT_2;
Parse1DMatrixAppend( shaderText, 3, cm->data ); Parse1DMatrixAppend( shaderText, 3, cm->data );
} }
/* dotProduct2scale ( X Y Z MIN MAX ) */ /* dotProduct2scale ( X Y Z MIN MAX ) */
else if ( striEqual( token, "dotProduct2scale" ) ) { else if ( striEqual( token, "dotProduct2scale" ) ) {
cm->type = CM_COLOR_DOT_PRODUCT_2_SCALE + alpha; cm->type = alpha? CM_ALPHA_DOT_PRODUCT_2_SCALE : CM_COLOR_DOT_PRODUCT_2_SCALE;
Parse1DMatrixAppend( shaderText, 5, cm->data ); Parse1DMatrixAppend( shaderText, 5, cm->data );
} }

View File

@ -388,7 +388,7 @@ void TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds ){
#define MAXAREA_MAXTRIES 8 #define MAXAREA_MAXTRIES 8
int MaxAreaIndexes( bspDrawVert_t *vert, int cnt, int *indexes ){ int MaxAreaIndexes( bspDrawVert_t *vert, int cnt, int *indexes ){
int r, s, t, bestR = 0, bestS = 1, bestT = 2; int r, s, t, bestR = 0, bestS = 1, bestT = 2;
int i, j, try; int i, j;
double A, bestA = -1, V, bestV = -1; double A, bestA = -1, V, bestV = -1;
vec3_t ab, ac, bc, cross; vec3_t ab, ac, bc, cross;
bspDrawVert_t *buf; bspDrawVert_t *buf;
@ -458,9 +458,9 @@ int MaxAreaIndexes( bspDrawVert_t *vert, int cnt, int *indexes ){
Sys_FPrintf( SYS_WRN, "value was REALLY bad\n" ); Sys_FPrintf( SYS_WRN, "value was REALLY bad\n" );
*/ */
for ( try = 0; try < MAXAREA_MAXTRIES; ++try ) for ( int trai = 0; trai < MAXAREA_MAXTRIES; ++trai )
{ {
if ( try ) { if ( trai ) {
bestR = rand() % cnt; bestR = rand() % cnt;
bestS = rand() % cnt; bestS = rand() % cnt;
bestT = rand() % cnt; bestT = rand() % cnt;
@ -604,7 +604,7 @@ void MaxAreaFaceSurface( mapDrawSurface_t *ds ){
void FanFaceSurface( mapDrawSurface_t *ds ){ void FanFaceSurface( mapDrawSurface_t *ds ){
int i, j, k, a, b, c; int i, j, k, a, b, c;
int color[ MAX_LIGHTMAPS ][ 4 ] = {0}; int color[ MAX_LIGHTMAPS ][ 4 ] = {{0}};
bspDrawVert_t *verts, *centroid, *dv; bspDrawVert_t *verts, *centroid, *dv;
double iv; double iv;

View File

@ -1412,7 +1412,8 @@ 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[p->winding->numpoints] ) ); memcpy( &in, p->winding, (size_t)((fixedWinding_t *)0)->points[p->winding->numpoints] );
// memcpy( &in, p->winding, offsetof( fixedWinding_t, points[p->winding->numpoints] ) );
} }
else{ else{
memcpy( &in, p->winding, sizeof( fixedWinding_t ) ); memcpy( &in, p->winding, sizeof( fixedWinding_t ) );