diff --git a/contrib/bobtoolz/DBrush.cpp b/contrib/bobtoolz/DBrush.cpp index 7c24cd0f..4a2b9c09 100644 --- a/contrib/bobtoolz/DBrush.cpp +++ b/contrib/bobtoolz/DBrush.cpp @@ -708,7 +708,7 @@ void DBrush::SaveToFile( FILE *pFile ){ ( *pp )->texInfo.m_texdef.scale[0], ( *pp )->texInfo.m_texdef.scale[0], ( *pp )->texInfo.m_texdef.rotate ); - fprintf( pFile, buffer ); + fprintf( pFile, "%s", buffer ); } fprintf( pFile, "}\n" ); diff --git a/libs/splines/splines.cpp b/libs/splines/splines.cpp index 42c34939..05cb3bf9 100644 --- a/libs/splines/splines.cpp +++ b/libs/splines/splines.cpp @@ -393,7 +393,6 @@ void idSplineList::setSelectedPoint( idVec3 *p ) { const idVec3 *idSplineList::getPosition( long t ) { static idVec3 interpolatedPos; - static long lastTime = -1; int count = splineTime.Num(); if ( count == 0 ) { @@ -644,7 +643,6 @@ bool idCameraDef::waitEvent( int index ) { void idCameraDef::buildCamera() { int i; - int lastSwitch = 0; idList waits; idList targets; @@ -653,7 +651,6 @@ void idCameraDef::buildCamera() { // we have a base time layout for the path and the target path // now we need to layer on any wait or speed changes for ( i = 0; i < events.Num(); i++ ) { - idCameraEvent *ev = events[i]; events[i]->setTriggered( false ); switch ( events[i]->getType() ) { case idCameraEvent::EVENT_TARGET: { @@ -864,7 +861,8 @@ void idCameraDef::parse( const char *( *text ) ) { bool idCameraDef::load( const char *filename ) { char *buf; const char *buf_p; - int length = FS_ReadFile( filename, (void **)&buf ); + + FS_ReadFile( filename, (void **)&buf ); if ( !buf ) { return false; } @@ -1363,7 +1361,6 @@ void idSplinePosition::write( fileHandle_t file, const char *p ) { } void idCameraDef::addTarget( const char *name, idCameraPosition::positionType type ) { - const char *text = ( name == NULL ) ? va( "target0%d", numTargets() + 1 ) : name; idCameraPosition *pos = newFromType( type ); if ( pos ) { pos->setName( name ); diff --git a/libs/splines/util_str.cpp b/libs/splines/util_str.cpp index 8ac9dea3..62fdaedc 100644 --- a/libs/splines/util_str.cpp +++ b/libs/splines/util_str.cpp @@ -487,9 +487,6 @@ void TestStringClass i = a.length(); // i == 0 i = c.length(); // i == 4 - const char *s1 = a.c_str(); // s1 == "\0" - const char *s2 = c.c_str(); // s2 == "test\0" - t = new idStr(); // t->len == 0, t->data == "\0" delete t; // t == ? diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index 5164001c..41fd1ca1 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -244,7 +244,10 @@ char *ExpandArg( const char *path ){ char *ExpandPath( const char *path ){ static char full[1024]; - if ( !*qdir || path[0] == '/' || path[0] == '\\' || path[1] == ':' ) { + if ( !qdir ) { + Error( "ExpandPath called without qdir set" ); + } + if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) { strcpy( full, path ); return full; } @@ -254,7 +257,7 @@ char *ExpandPath( const char *path ){ char *ExpandGamePath( const char *path ){ static char full[1024]; - if ( !*gamedir ) { + if ( !gamedir[0] ) { Error( "ExpandGamePath called without gamedir set" ); } if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) { diff --git a/tools/quake3/common/cmdlib.h b/tools/quake3/common/cmdlib.h index 3c9b5a54..f6f5e4d1 100644 --- a/tools/quake3/common/cmdlib.h +++ b/tools/quake3/common/cmdlib.h @@ -56,7 +56,7 @@ #ifdef PATH_MAX #define MAX_OS_PATH PATH_MAX #else -#define MAX_OS_PATH 1024 +#define MAX_OS_PATH 4096 #endif #define MEM_BLOCKSIZE 4096 diff --git a/tools/quake3/common/inout.c b/tools/quake3/common/inout.c index 6920995f..2c1758a7 100644 --- a/tools/quake3/common/inout.c +++ b/tools/quake3/common/inout.c @@ -43,6 +43,7 @@ #include "libxml/tree.h" // utf8 conversion +#include #include #include diff --git a/tools/quake3/q3map2/main.c b/tools/quake3/q3map2/main.c index b53a6973..76591a2a 100644 --- a/tools/quake3/q3map2/main.c +++ b/tools/quake3/q3map2/main.c @@ -48,6 +48,38 @@ vec_t Random( void ){ } +char *Q_strncpyz( char *dst, const char *src, size_t len ) { + if ( len == 0 ) { + abort(); + } + + strncpy( dst, src, len ); + dst[ len - 1 ] = '\0'; + return dst; +} + + +char *Q_strcat( char *dst, size_t dlen, const char *src ) { + size_t n = strlen( dst ); + + if ( n > dlen ) { + abort(); /* buffer overflow */ + } + + return Q_strncpyz( dst + n, src, dlen - n ); +} + + +char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) { + size_t n = strlen( dst ); + + if ( n > dlen ) { + abort(); /* buffer overflow */ + } + + return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) ); +} + /* ExitQ3Map() diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 2591c5bf..07ebc31b 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -66,26 +66,21 @@ char *LokiGetHomeDir( void ){ #ifndef Q_UNIX return NULL; #else + static char buf[ 4096 ]; + struct passwd pw, *pwp; char *home; - uid_t id; - struct passwd *pwd; static char homeBuf[MAX_OS_PATH]; /* get the home environment variable */ home = getenv( "HOME" ); - if ( home == NULL ) { - /* do some more digging */ - id = getuid(); - setpwent(); - while ( ( pwd = getpwent() ) != NULL ) - { - if ( pwd->pw_uid == id ) { - home = pwd->pw_dir; - break; - } + + /* look up home dir in password database */ + if(!home) + { + if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) { + return pw.pw_dir; } - endpwent(); } snprintf( homeBuf, sizeof( homeBuf ), "%s/.", home ); @@ -130,21 +125,16 @@ void LokiInitPaths( char *argv0 ){ qboolean found; + path = getenv( "PATH" ); + /* do some path divining */ - strcpy( temp, argv0 ); - if ( strrchr( argv0, '/' ) ) { + Q_strncpyz( temp, argv0, sizeof( temp ) ); + if ( strrchr( temp, '/' ) ) { argv0 = strrchr( argv0, '/' ) + 1; } - else - { - /* get path environment variable */ - path = getenv( "PATH" ); - - /* minor setup */ - last = last0; - last[ 0 ] = path[ 0 ]; - last[ 1 ] = '\0'; + else if ( path ) { found = qfalse; + last = path; /* go through each : segment of path */ while ( last[ 0 ] != '\0' && found == qfalse ) @@ -160,17 +150,17 @@ void LokiInitPaths( char *argv0 ){ /* found home dir candidate */ if ( *path == '~' ) { - strcpy( temp, home ); + Q_strncpyz( temp, home, sizeof( temp ) ); path++; } /* concatenate */ if ( last > ( path + 1 ) ) { - strncat( temp, path, ( last - path ) ); - strcat( temp, "/" ); + Q_strncat( temp, sizeof( temp ), path, ( last - path ) ); + Q_strcat( temp, sizeof( temp ), "/" ); } - strcat( temp, "./" ); - strcat( temp, argv0 ); + Q_strcat( temp, sizeof( temp ), "./" ); + Q_strcat( temp, sizeof( temp ), argv0 ); /* verify the path */ if ( access( temp, X_OK ) == 0 ) { diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 935d1c7f..bbb3e76e 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -85,6 +85,8 @@ #include "md4.h" #include +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) /* ------------------------------------------------------------------------------- @@ -1512,6 +1514,9 @@ surfaceInfo_t; /* main.c */ vec_t Random( void ); +char *Q_strncpyz( char *dst, const char *src, size_t len ); +char *Q_strcat( char *dst, size_t dlen, const char *src ); +char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ); int BSPInfo( int count, char **fileNames ); int ScaleBSPMain( int argc, char **argv ); int ConvertMain( int argc, char **argv );