diff options
author | M. Kristall <mkpdev@gmail.com> | 2009-10-03 11:41:43 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:15:14 +0000 |
commit | 74ff891914c7f91b0f6c86a7a075a4fafdaf15e5 (patch) | |
tree | f415232f36f56a673d29bd7a06577be14f2e9fc5 | |
parent | 614a658030e59212335611596adb196b93e5b437 (diff) |
* Fix a couple more places where files might not be closed (bug 3554)
* Fix off-by-one errors and some gcc warnings
-rw-r--r-- | src/cgame/cg_buildable.c | 14 | ||||
-rw-r--r-- | src/cgame/cg_particles.c | 8 | ||||
-rw-r--r-- | src/cgame/cg_ptr.c | 7 | ||||
-rw-r--r-- | src/cgame/cg_trails.c | 6 | ||||
-rw-r--r-- | src/game/bg_misc.c | 16 | ||||
-rw-r--r-- | src/game/g_admin.c | 10 | ||||
-rw-r--r-- | src/game/g_client.c | 2 |
7 files changed, 38 insertions, 25 deletions
diff --git a/src/cgame/cg_buildable.c b/src/cgame/cg_buildable.c index ae0ed17e..00e2c2c2 100644 --- a/src/cgame/cg_buildable.c +++ b/src/cgame/cg_buildable.c @@ -169,12 +169,13 @@ static qboolean CG_ParseBuildableAnimationFile( const char *filename, buildable_ // load the file len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if( len <= 0 ) + if( len < 0 ) return qfalse; - if( len >= sizeof( text ) - 1 ) + if( len == 0 || len >= sizeof( text ) - 1 ) { - CG_Printf( "File %s too long\n", filename ); + trap_FS_FCloseFile( f ); + CG_Printf( "File %s is %s\n", filename, len == 0 ? "empty" : "too long" ); return qfalse; } @@ -259,12 +260,13 @@ static qboolean CG_ParseBuildableSoundFile( const char *filename, buildable_t bu // load the file len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if ( len <= 0 ) + if ( len < 0 ) return qfalse; - if ( len >= sizeof( text ) - 1 ) + if ( len == 0 || len >= sizeof( text ) - 1 ) { - CG_Printf( "File %s too long\n", filename ); + trap_FS_FCloseFile( f ); + CG_Printf( "File %s is %s\n", filename, len == 0 ? "empty" : "too long" ); return qfalse; } diff --git a/src/cgame/cg_particles.c b/src/cgame/cg_particles.c index c7023dbf..1f4bb4ca 100644 --- a/src/cgame/cg_particles.c +++ b/src/cgame/cg_particles.c @@ -1622,12 +1622,14 @@ static qboolean CG_ParseParticleFile( const char *fileName ) // load the file len = trap_FS_FOpenFile( fileName, &f, FS_READ ); - if( len <= 0 ) + if( len < 0 ) return qfalse; - if( len >= sizeof( text ) - 1 ) + if( len == 0 || len >= sizeof( text ) - 1 ) { - CG_Printf( S_COLOR_RED "ERROR: particle file %s too long\n", fileName ); + trap_FS_FCloseFile( f ); + CG_Printf( S_COLOR_RED "ERROR: particle file %s is %s\n", fileName, + len == 0 ? "empty" : "too long" ); return qfalse; } diff --git a/src/cgame/cg_ptr.c b/src/cgame/cg_ptr.c index 18810878..b5fa548e 100644 --- a/src/cgame/cg_ptr.c +++ b/src/cgame/cg_ptr.c @@ -42,12 +42,15 @@ int CG_ReadPTRCode( void ) // load the file len = trap_FS_FOpenFile( PTRC_FILE, &f, FS_READ ); - if( len <= 0 ) + if( len < 0 ) return 0; // should never happen - malformed write - if( len >= sizeof( text ) - 1 ) + if( len == 0 || len >= sizeof( text ) - 1 ) + { + trap_FS_FCloseFile( f ); return 0; + } trap_FS_Read( text, len, f ); text[ len ] = 0; diff --git a/src/cgame/cg_trails.c b/src/cgame/cg_trails.c index ca610461..f1fb0f5b 100644 --- a/src/cgame/cg_trails.c +++ b/src/cgame/cg_trails.c @@ -1060,9 +1060,11 @@ static qboolean CG_ParseTrailFile( const char *fileName ) if( len <= 0 ) return qfalse; - if( len >= sizeof( text ) - 1 ) + if( len == 0 || len >= sizeof( text ) - 1 ) { - CG_Printf( S_COLOR_RED "ERROR: trail file %s too long\n", fileName ); + trap_FS_FCloseFile( f ); + CG_Printf( S_COLOR_RED "ERROR: trail file %s is %s\n", fileName, + len == 0 ? "empty" : "too long" ); return qfalse; } diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c index 8f03f098..6c63d648 100644 --- a/src/game/bg_misc.c +++ b/src/game/bg_misc.c @@ -1455,12 +1455,14 @@ static qboolean BG_ParseBuildableFile( const char *filename, buildableAttributeO // load the file len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if( len <= 0 ) + if( len < 0 ) return qfalse; - if( len >= sizeof( text ) - 1 ) + if( len == 0 || len >= sizeof( text ) - 1 ) { - Com_Printf( S_COLOR_RED "ERROR: Buildable file %s too long\n", filename ); + trap_FS_FCloseFile( f ); + Com_Printf( S_COLOR_RED "ERROR: Buildable file %s is %s\n", filename, + len == 0 ? "empty" : "too long" ); return qfalse; } @@ -2991,12 +2993,14 @@ static qboolean BG_ParseClassFile( const char *filename, classAttributeOverrides // load the file len = trap_FS_FOpenFile( filename, &f, FS_READ ); - if( len <= 0 ) + if( len < 0 ) return qfalse; - if( len >= sizeof( text ) - 1 ) + if( len == 0 || len >= sizeof( text ) - 1 ) { - Com_Printf( S_COLOR_RED "ERROR: Class file %s too long\n", filename ); + trap_FS_FCloseFile( f ); + Com_Printf( S_COLOR_RED "ERROR: Class file %s is %s\n", filename, + len == 0 ? "empty" : "too long" ); return qfalse; } diff --git a/src/game/g_admin.c b/src/game/g_admin.c index deaedf35..bf0bba33 100644 --- a/src/game/g_admin.c +++ b/src/game/g_admin.c @@ -752,7 +752,7 @@ static int admin_listadmins( gentity_t *ent, int start, char *search ) if( !strstr( name, search ) ) continue; - for( j = 0; j <= 8; j++ ) + for( j = 0; j < 8; j++ ) guid_stub[ j ] = vic->client->pers.guid[ j + 24 ]; guid_stub[ j ] = '\0'; @@ -808,7 +808,7 @@ static int admin_listadmins( gentity_t *ent, int start, char *search ) if( dup ) continue; } - for( j = 0; j <= 8; j++ ) + for( j = 0; j < 8; j++ ) guid_stub[ j ] = g_admin_admins[ i ]->guid[ j + 24 ]; guid_stub[ j ] = '\0'; @@ -1765,7 +1765,7 @@ qboolean G_admin_ban( gentity_t *ent, int skiparg ) ADMBP( "^3!ban: ^7multiple recent clients match name, use IP or slot#:\n" ); for( i = 0; i < MAX_ADMIN_NAMELOGS && g_admin_namelog[ i ]; i++ ) { - for( j = 0; j <= 8; j++ ) + for( j = 0; j < 8; j++ ) guid_stub[ j ] = g_admin_namelog[ i ]->guid[ j + 24 ]; guid_stub[ j ] = '\0'; for( j = 0; j < MAX_ADMIN_NAMELOG_NAMES && @@ -2253,7 +2253,7 @@ qboolean G_admin_listplayers( gentity_t *ent, int skiparg ) continue; } - for( j = 0; j <= 8; j++ ) + for( j = 0; j < 8; j++ ) guid_stub[ j ] = p->pers.guid[ j + 24 ]; guid_stub[ j ] = '\0'; @@ -2829,7 +2829,7 @@ qboolean G_admin_namelog( gentity_t *ent, int skiparg ) continue; } printed++; - for( j = 0; j <= 8; j++ ) + for( j = 0; j < 8; j++ ) guid_stub[ j ] = g_admin_namelog[ i ]->guid[ j + 24 ]; guid_stub[ j ] = '\0'; if( g_admin_namelog[ i ]->slot > -1 ) diff --git a/src/game/g_client.c b/src/game/g_client.c index aa91cd46..eec9d3eb 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -766,7 +766,7 @@ void respawn( gentity_t *ent ) /* =========== -ClientCheckName +ClientCleanName ============ */ static void ClientCleanName( const char *in, char *out, int outSize ) |