]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Merge pull request #6 from bnoordhuis/cleanup
authorTimothee "TTimo" Besset <ttimo@ttimo.net>
Sun, 18 Mar 2012 13:52:13 +0000 (06:52 -0700)
committerTimothee "TTimo" Besset <ttimo@ttimo.net>
Sun, 18 Mar 2012 13:52:13 +0000 (06:52 -0700)
cleanup + q3map2 crash fix

18 files changed:
.gitignore
config.py
contrib/bobtoolz/DBrush.cpp
libs/splines/splines.cpp
libs/splines/util_str.cpp
libs/synapse/synapse.cpp
plugins/imagehl/lbmlib.cpp
plugins/surface_heretic2/surfacedialog.cpp
plugins/surface_ufoai/surfacedialog.cpp
radiant/brushscript.cpp
radiant/main.cpp
tools/quake3/common/cmdlib.c
tools/quake3/common/cmdlib.h
tools/quake3/common/inout.c
tools/quake3/q3map2/light_ydnar.c
tools/quake3/q3map2/main.c
tools/quake3/q3map2/path_init.c
tools/quake3/q3map2/q3map2.h

index e92ff2c3e760b9e4d196afc0af4f4faefdc5d2de..c1704fc5e624ec5c248abba7c8ec8b344ab0ad2c 100644 (file)
@@ -1,2 +1,7 @@
-
-# /
+/install/q3map2
+/install/radiant.bin
+/.sconsign.dblite
+/site.sconf
+/build
+*.pyc
+*.so
index f55b7bfa14860159c05ea6df74b155fc37d30b5b..4c441393ff8fbff47d5832feca409414fff0f398 100644 (file)
--- a/config.py
+++ b/config.py
@@ -247,9 +247,8 @@ class Config:
                        env.Append( CXXFLAGS = [ '-g' ] )
                        env.Append( CPPDEFINES = [ '_DEBUG' ] )
                else:
-                        # '-O' causes q3map2 errors on Ubuntu 10.10 32 bit.
-                       env.Append( CFLAGS = [ ] )
-                       env.Append( CXXFLAGS = [ ] )
+                       env.Append( CFLAGS = [ '-O2', '-fno-strict-aliasing' ] )
+                       env.Append( CXXFLAGS = [ '-O2', '-fno-strict-aliasing' ] )
 
        def CheckoutOrUpdate( self, svnurl, path ):
                if ( os.path.exists( path ) ):
index 34afabfea52a288ece82dcda0844d96059666cdc..3e54e79717b554c6857a43bf87c721fb48dedc85 100644 (file)
@@ -694,7 +694,7 @@ void DBrush::SaveToFile( FILE *pFile ){
                                 ( *pp )->texInfo.m_fScale[0], ( *pp )->texInfo.m_fScale[0],
                                 ( *pp )->texInfo.m_fRotate );
 
-               fprintf( pFile, buffer );
+               fprintf( pFile, "%s", buffer );
        }
 
        fprintf( pFile, "}\n" );
index c0d95c01a129e2505ce0a248232674b490655095..b9b7c0c90e4907514e497ed252f2356a8bcdc3f4 100644 (file)
@@ -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<float> waits;
        idList<int> 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 );
index eb51533c93cfbfa57954b726e7caab6efbddde2c..52a01a365fa592f875416a47b09657c54e285852 100644 (file)
@@ -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 == ?
 
index 482204fdd0e0faf2e051036de1a2cd344ede4475..c4dd78cce5ad4087b1645a6a2080ef657c00b048 100644 (file)
@@ -65,7 +65,7 @@ void Syn_Printf( const char *text, ... ){
                va_start( args, text );
                vsnprintf( buf, BUFFER_SIZE, text, args );
                buf[BUFFER_SIZE - 1] = 0;
-               printf( buf );
+               printf( "%s", buf );
                va_end( args );
        }
 }
index 9262cda2bf91913e30394284deb39a9835306c46..beb83b6db43bdeecd3c229fb2551b01603ac2ded 100644 (file)
@@ -133,8 +133,6 @@ static void LoadIDSP( const char *name, byte ** pic, int *width, int *height ){
        dspriteframetype_t  *pframetype;
        int version;
        int numframes;
-       int size;
-       spriteframetype_t frametype;
        dspriteframe_t *spriteframe;
 
        *pic = NULL;
@@ -201,7 +199,7 @@ static void LoadIDSP( const char *name, byte ** pic, int *width, int *height ){
        *pic = bmpRGBA;
 
 #ifdef DEBUG
-       frametype = spriteframetype_t( LittleLong( pframetype->type ) );
+       spriteframetype_t frametype = spriteframetype_t( LittleLong( pframetype->type ) );
        if ( frametype == SPR_SINGLE ) {
                Sys_Printf( "Single Frame\n" );
        }
index 829ad8d99e0644f5c199bcaf813900f8ee1a784a..fd06da6dc522ea72f7cfbe7cb35ce5f68e0350b2 100644 (file)
@@ -219,7 +219,6 @@ static void on_cancel_button_clicked( GtkButton *button, gpointer user_data );
 void IsFaceConflicting(){
        texdef_t* tmp_texdef;
        texdef_to_face_t* temp_texdef_face_list;
-       char buf[12];
        char texture_name[128];
 
        if ( texdef_face_list_empty() ) {
@@ -328,7 +327,6 @@ static void PopulateTextureComboList(){
        texdef_to_face_t* temp_texdef_face_list;
        char blank[1];
        GList *items = NULL;
-       GList *tmp_item;
        int num_of_list_items = 0;
 
        blank[0] = 0;
@@ -390,7 +388,6 @@ static void GetTexdefInfo_from_Radiant(){
        g_texdef_face_vector.resize( count );
 
        if ( !texdef_face_list_empty() ) {
-               texdef_to_face_t* p = get_texdef_face_list();
                GetSelFacesTexdef( get_texdef_face_list() );
        }
 
@@ -1861,7 +1858,6 @@ static void on_fit_button_clicked( GtkButton *button, gpointer user_data ){
 // Axial Button
 static void on_axial_button_clicked( GtkButton *button, gpointer user_data ){
        texdef_t* tmp_texdef;
-       texdef_t* tmp_orig_texdef;
        texdef_to_face_t* temp_texdef_face_list;
 
        if ( !texdef_face_list_empty() && g_bListenChanged ) {
index c6b9f0c82090983e13788409aa68ecd5f6b1a27e..5e0eebc28baca3066875de4197e4fdcb0b39054e 100644 (file)
@@ -220,7 +220,6 @@ static void on_cancel_button_clicked( GtkButton *button, gpointer user_data );
 void IsFaceConflicting(){
        texdef_t* tmp_texdef;
        texdef_to_face_t* temp_texdef_face_list;
-       char buf[12];
        char texture_name[128];
 
        if ( texdef_face_list_empty() ) {
@@ -329,7 +328,6 @@ static void PopulateTextureComboList(){
        texdef_to_face_t* temp_texdef_face_list;
        char blank[1];
        GList *items = NULL;
-       GList *tmp_item;
        int num_of_list_items = 0;
 
        blank[0] = 0;
@@ -391,7 +389,6 @@ static void GetTexdefInfo_from_Radiant(){
        g_texdef_face_vector.resize( count );
 
        if ( !texdef_face_list_empty() ) {
-               texdef_to_face_t* p = get_texdef_face_list();
                GetSelFacesTexdef( get_texdef_face_list() );
        }
 
@@ -1861,7 +1858,6 @@ static void on_fit_button_clicked( GtkButton *button, gpointer user_data ){
 // Axial Button
 static void on_axial_button_clicked( GtkButton *button, gpointer user_data ){
        texdef_t* tmp_texdef;
-       texdef_t* tmp_orig_texdef;
        texdef_to_face_t* temp_texdef_face_list;
 
        if ( !texdef_face_list_empty() && g_bListenChanged ) {
index 359fd29996c755ba9e04c09428fb4cf886595b9d..d056b56b52c24a6f53db3aaa1252af9cba4f2667 100644 (file)
@@ -426,42 +426,28 @@ void Input( char*& pBuffer ){
        const char *fields[5] = { "", "", "", "", "" };
        float values[5];
 
-       for ( int n = 0; n < g_nVariableCount; n++ )
+       for ( int n = 0; n < 5 && n < g_nVariableCount; n++ )
        {
                if ( g_Variables[n].m_strInput.GetLength() > 0 ) {
                        bGo = true;
-                       if ( n < 5 ) {
-                               switch ( n )
-                               {
-                               case 0: fields[1] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 1: fields[2] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 2: fields[3] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 3: fields[4] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               case 4: fields[5] = g_Variables[n].m_strInput.GetBuffer(); break;
-                               }
-                       }
+                       fields[n] = g_Variables[n].m_strInput.GetBuffer();
                }
        }
 
-       if ( bGo ) {
-               if ( DoBSInputDlg( fields, values ) == IDOK ) {
-                       for ( int n = 0; n < g_nVariableCount; n++ )
-                       {
-                               if ( g_Variables[n].m_strInput.GetLength() > 0 ) {
-                                       if ( n < 5 ) {
-                                               switch ( n )
-                                               {
-                                               case 0: g_Variables[n].m_fValue = values[1]; break;
-                                               case 1: g_Variables[n].m_fValue = values[2]; break;
-                                               case 2: g_Variables[n].m_fValue = values[3]; break;
-                                               case 3: g_Variables[n].m_fValue = values[4]; break;
-                                               case 4: g_Variables[n].m_fValue = values[5]; break;
-                                               }
-                                       }
-                               }
-                       }
+       if ( !bGo ) {
+               return;
+       }
+
+       if ( DoBSInputDlg( fields, values ) != IDOK ) {
+               g_bKeepGoing = false;
+               return;
+       }
+
+       for ( int n = 0; n < 5 && n < g_nVariableCount; n++ )
+       {
+               if ( g_Variables[n].m_strInput.GetLength() > 0 ) {
+                       g_Variables[n].m_fValue = values[n];
                }
-               else{ g_bKeepGoing = false; }
        }
 }
 
index 8e26926f7cb6583284d1e0d429bd8d862f71c10a..2fa5221419e921720380c648aa507a1ccda815a2 100644 (file)
@@ -1145,7 +1145,7 @@ void RunBsp( char *command ){
                        Error( "Can't write to %s", batpath );
                }
                fprintf( hFile, "#!/bin/sh \n\n" );
-               fprintf( hFile, strSys.GetBuffer() );
+               fprintf( hFile, "%s", strSys.GetBuffer() );
                fclose( hFile );
                chmod( batpath, 0744 );
 #endif
@@ -1158,7 +1158,7 @@ void RunBsp( char *command ){
                if ( !hFile ) {
                        Error( "Can't write to %s", batpath );
                }
-               fprintf( hFile, strSys.GetBuffer() );
+               fprintf( hFile, "%s", strSys.GetBuffer() );
                fclose( hFile );
 #endif
 
index 5f20773f772378b9f1814f566f3331d1e7d39d54..35f4d75bd68dcb0767c820e73963420a8607c1c8 100644 (file)
@@ -244,7 +244,7 @@ char *ExpandArg( const char *path ){
 
 char *ExpandPath( const char *path ){
        static char full[1024];
-       if ( !qdir ) {
+       if ( !qdir[0] ) {
                Error( "ExpandPath called without qdir set" );
        }
        if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) {
@@ -257,7 +257,7 @@ char *ExpandPath( const char *path ){
 
 char *ExpandGamePath( const char *path ){
        static char full[1024];
-       if ( !qdir ) {
+       if ( !qdir[0] ) {
                Error( "ExpandGamePath called without qdir set" );
        }
        if ( path[0] == '/' || path[0] == '\\' || path[1] == ':' ) {
index e7b555b40b989028b5f4c5a74fbf0a13e3a988b2..3fb98febc98457d9438a089882a41f937dfa0f6d 100644 (file)
@@ -53,7 +53,7 @@
 #endif
 
 
-#define MAX_OS_PATH     1024
+#define MAX_OS_PATH     4096
 #define MEM_BLOCKSIZE 4096
 
 // the dec offsetof macro doesnt work very well...
index 74a111b8eaa5575515019cfc69e660ffcb3e7655..acf492a295d840be308741607564a256e83ec90f 100644 (file)
@@ -264,7 +264,7 @@ void FPrintf( int flag, char *buf ){
        static qboolean bGotXML = qfalse;
        char level[2];
 
-       printf( buf );
+       printf( "%s", buf );
 
        // the following part is XML stuff only.. but maybe we don't want that message to go down the XML pipe?
        if ( flag == SYS_NOXML ) {
index 794f2cb8e06390725f41b3e44f17ad07f9d21887..cb0430ea3a0f77ee30ac105415b2826dc6c75de3 100644 (file)
@@ -3179,7 +3179,7 @@ void SetupEnvelopes( qboolean forGrid, qboolean fastFlag ){
        int i, x, y, z, x1, y1, z1;
        light_t     *light, *light2, **owner;
        bspLeaf_t   *leaf;
-       vec3_t origin, dir, mins, maxs, nullVector = { 0, 0, 0 };
+       vec3_t origin, dir, mins, maxs;
        float radius, intensity;
        light_t     *buckets[ 256 ];
 
index 2ea7c9236160f6c7706598f828f097d088d1af3c..e74a89cfc76141b124fc1f030a59b61d3a1cc9ef 100644 (file)
@@ -46,6 +46,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()
index 6bd061350d7327034afa11167f5fcb89af4139f1..901f07fc3f64db841221fd26e82558564fab6d29 100644 (file)
@@ -66,29 +66,23 @@ 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;
 
 
        /* 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;
-                       }
-               }
-               endpwent();
+       if ( home ) {
+               return Q_strncpyz( buf, home, sizeof( buf ) );
+       }
+
+       /* look up home dir in password database */
+       if ( getpwuid_r( getuid(), &pw, buf, sizeof( buf ), &pwp ) == 0 ) {
+               return pw.pw_dir;
        }
 
-       /* return it */
-       return home;
+       return NULL;
        #endif
 }
 
@@ -117,20 +111,16 @@ void LokiInitPaths( char *argv0 ){
                home = ".";
        }
 
+       path = getenv( "PATH" );
+
        /* do some path divining */
-       strcpy( temp, 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[ 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 )
@@ -146,17 +136,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 ) {
index bb7569152870610c4cf480c17c3780515a3eab38..245e34c6cb34298ff989684bcf3db4adbc129f32 100644 (file)
@@ -83,6 +83,8 @@
 
 #include <stdlib.h>
 
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
 
 
 /* -------------------------------------------------------------------------------
@@ -1446,6 +1448,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 );