Skip to content

Commit

Permalink
[MP] Properly close file handles in the case of errors. Also fixed so…
Browse files Browse the repository at this point in the history
…me flag unsetting (EF_SOUNDTRACKER, WPFLAG_GOALPOINT)
  • Loading branch information
Razish committed Dec 24, 2017
1 parent 41bd4d8 commit efbeb7c
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion codemp/cgame/cg_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -3121,7 +3121,7 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {
DEBUGNAME("EV_MUTE_SOUND");
if (cg_entities[es->trickedentindex2].currentState.eFlags & EF_SOUNDTRACKER)
{
cg_entities[es->trickedentindex2].currentState.eFlags -= EF_SOUNDTRACKER;
cg_entities[es->trickedentindex2].currentState.eFlags &= ~EF_SOUNDTRACKER;
}
trap->S_MuteSound(es->trickedentindex2, es->trickedentindex);
CG_S_StopLoopingSound(es->trickedentindex2, -1);
Expand Down
1 change: 1 addition & 0 deletions codemp/cgame/cg_players.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ qboolean CG_ParseSurfsFile( const char *modelName, const char *skinName, char *s
if ( len >= sizeof( text ) - 1 )
{
Com_Printf( "File %s too long\n", sfilename );
trap->FS_Close( f );
return qfalse;
}

Expand Down
7 changes: 5 additions & 2 deletions codemp/cgame/cg_saga.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ void CG_InitSiegeMode(void)

len = trap->FS_Open(levelname, &f, FS_READ);

if (!f || len >= MAX_SIEGE_INFO_SIZE)
{
if ( !f ) {
goto failure;
}
if ( len >= MAX_SIEGE_INFO_SIZE ) {
trap->FS_Close( f );
goto failure;
}

Expand Down
1 change: 1 addition & 0 deletions codemp/game/NPC_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -3591,6 +3591,7 @@ void NPC_LoadParms( void )
else
{
if ( totallen + len >= MAX_NPC_DATA_SIZE ) {
trap->FS_Close( f );
trap->Error( ERR_DROP, "NPC extensions (*.npc) are too large" );
}
trap->FS_Read(npcParseBuffer, len, f);
Expand Down
1 change: 1 addition & 0 deletions codemp/game/ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ void BotUtilizePersonality(bot_state_t *bs)
{
trap->Print(S_COLOR_RED "Personality file exceeds maximum length\n");
B_TempFree(131072); //buf
trap->FS_Close( f );
return;
}

Expand Down
7 changes: 4 additions & 3 deletions codemp/game/ai_wpnav.c
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ void CalculateWeightGoals(void)

if (gWPArray[i]->flags & WPFLAG_GOALPOINT)
{
gWPArray[i]->flags -= WPFLAG_GOALPOINT;
gWPArray[i]->flags &= ~WPFLAG_GOALPOINT;
}
}

Expand Down Expand Up @@ -2047,6 +2047,7 @@ int LoadPathData(const char *filename)
if (len >= 524288)
{
trap->Print(S_COLOR_RED "Route file exceeds maximum length\n");
trap->FS_Close( f );
return 0;
}

Expand Down Expand Up @@ -3709,11 +3710,11 @@ int AcceptBotCommand(char *cmd, gentity_t *pl)
{
if (gWPArray[i]->flags & WPFLAG_ONEWAY_FWD)
{
gWPArray[i]->flags -= WPFLAG_ONEWAY_FWD;
gWPArray[i]->flags &= ~WPFLAG_ONEWAY_FWD;
}
if (gWPArray[i]->flags & WPFLAG_ONEWAY_BACK)
{
gWPArray[i]->flags -= WPFLAG_ONEWAY_BACK;
gWPArray[i]->flags &= ~WPFLAG_ONEWAY_BACK;
}
}

Expand Down
28 changes: 6 additions & 22 deletions codemp/game/bg_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,31 +322,15 @@ int WeaponAttackAnim[WP_NUM_WEAPONS] =
BOTH_ATTACK1//WP_TURRET,
};

qboolean BG_FileExists(const char *fileName)
{
if (fileName && fileName[0])
{
int fh = 0;
#ifdef _GAME
trap->FS_Open(fileName, &fh, FS_READ);
#elif _CGAME
trap->FS_Open(fileName, &fh, FS_READ);
#elif UI_BUILD
trap->FS_Open(fileName, &fh, FS_READ);
#endif
if (fh > 0)
{
#ifdef _GAME
trap->FS_Close(fh);
#elif _CGAME
trap->FS_Close(fh);
#elif UI_BUILD
trap->FS_Close(fh);
#endif
qboolean BG_FileExists( const char *fileName ) {
if ( fileName && fileName[0] ) {
fileHandle_t f = NULL_FILE;
trap->FS_Open( fileName, &f, FS_READ );
if ( f > 0 ) {
trap->FS_Close( f );
return qtrue;
}
}

return qfalse;
}

Expand Down
1 change: 1 addition & 0 deletions codemp/game/bg_panimate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,7 @@ int BG_ParseAnimationFile(const char *filename, animation_t *animset, qboolean i
len = trap->FS_Open( filename, &f, FS_READ );
if ( (len <= 0) || (len >= sizeof( BGPAFtext ) - 1) )
{
trap->FS_Close( f );
if (dynAlloc)
{
BG_AnimsetFree(animset);
Expand Down
3 changes: 2 additions & 1 deletion codemp/game/bg_saberLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -2281,12 +2281,13 @@ void WP_SaberLoadParms( void )

len = trap->FS_Open( va( "ext_data/sabers/%s", holdChar ), &f, FS_READ );

if ( len == -1 ) {
if ( !f ) {
Com_Printf( "WP_SaberLoadParms: error reading file: %s\n", holdChar );
continue;
}

if ( (totallen + len+1) >= MAX_SABER_DATA_SIZE ) {
trap->FS_Close( f );
#ifdef UI_BUILD
Com_Error( ERR_FATAL, "WP_SaberLoadParms: Saber extensions (*.sab) are too large!\nRan out of space before reading %s", holdChar );
#else
Expand Down
14 changes: 10 additions & 4 deletions codemp/game/bg_saga.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,11 @@ void BG_SiegeParseClassFile(const char *filename, siegeClassDesc_t *descBuffer)

len = trap->FS_Open( filename, &f, FS_READ );

if (!f || len >= 4096)
{
if (!f) {
return;
}
if (len >= 4096) {
trap->FS_Close( f );
return;
}

Expand Down Expand Up @@ -1265,8 +1268,11 @@ void BG_SiegeParseTeamFile(const char *filename)

len = trap->FS_Open(filename, &f, FS_READ);

if (!f || len >= 2048)
{
if (!f) {
return;
}
if (len >= 2048) {
trap->FS_Close( f );
return;
}

Expand Down
2 changes: 2 additions & 0 deletions codemp/game/bg_vehicleLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ void BG_VehWeaponLoadParms( void )
}

if ( totallen + len >= MAX_VEH_WEAPON_DATA_SIZE ) {
trap->FS_Close( f );
Com_Error(ERR_DROP, "Vehicle Weapon extensions (*.vwp) are too large" );
}
strcat( marker, tempReadBuffer );
Expand Down Expand Up @@ -1386,6 +1387,7 @@ void BG_VehicleLoadParms( void )
}

if ( totallen + len >= MAX_VEHICLE_DATA_SIZE ) {
trap->FS_Close( f );
Com_Error(ERR_DROP, "Vehicle extensions (*.veh) are too large" );
}
strcat( marker, tempReadBuffer );
Expand Down
7 changes: 5 additions & 2 deletions codemp/game/g_saga.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ void InitSiegeMode(void)

len = trap->FS_Open(levelname, &f, FS_READ);

if (!f || len >= MAX_SIEGE_INFO_SIZE)
{
if (!f) {
goto failure;
}
if (len >= MAX_SIEGE_INFO_SIZE) {
trap->FS_Close( f );
goto failure;
}

Expand Down
11 changes: 4 additions & 7 deletions codemp/game/g_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,8 @@ static void G_SpewEntList(void)
char className[MAX_STRING_CHARS];
gentity_t *ent;
char *str;
#ifdef FINAL_BUILD
#define VM_OR_FINAL_BUILD
#endif

#ifndef VM_OR_FINAL_BUILD
#ifdef _DEBUG
fileHandle_t fh;
trap->FS_Open("entspew.txt", &fh, FS_WRITE);
#endif
Expand Down Expand Up @@ -753,7 +750,7 @@ static void G_SpewEntList(void)

str = va("TEMPENT %4i: EV %i\n", ent->s.number, ent->s.eType-ET_EVENTS);
Com_Printf(str);
#ifndef VM_OR_FINAL_BUILD
#ifdef _DEBUG
if (fh)
{
trap->FS_Write(str, strlen(str), fh);
Expand All @@ -771,7 +768,7 @@ static void G_SpewEntList(void)
}
str = va("ENT %4i: Classname %s\n", ent->s.number, className);
Com_Printf(str);
#ifndef VM_OR_FINAL_BUILD
#ifdef _DEBUG
if (fh)
{
trap->FS_Write(str, strlen(str), fh);
Expand All @@ -784,7 +781,7 @@ static void G_SpewEntList(void)

str = va("TempEnt count: %i\nTempEnt ST: %i\nNPC count: %i\nProjectile count: %i\n", numTempEnt, numTempEntST, numNPC, numProjectile);
Com_Printf(str);
#ifndef VM_OR_FINAL_BUILD
#ifdef _DEBUG
if (fh)
{
trap->FS_Write(str, strlen(str), fh);
Expand Down
1 change: 1 addition & 0 deletions codemp/ui/ui_force.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ void UI_ForceConfigHandle( int oldindex, int newindex )

if (len >= 8192)
{
trap->FS_Close( f );
return;
}

Expand Down
19 changes: 11 additions & 8 deletions codemp/ui/ui_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,13 @@ int UI_ParseAnimationFile(const char *filename, animation_t *animset, qboolean i
if (!UIPAFtextLoaded || !isHumanoid)
{ //rww - We are always using the same animation config now. So only load it once.
len = trap->FS_Open( filename, &f, FS_READ );
if ( (len <= 0) || (len >= sizeof( UIPAFtext ) - 1) )
{
if (len > 0)
{
Com_Error(ERR_DROP, "%s exceeds the allowed ui-side animation buffer!", filename);
}
if ( !f ) {
return -1;
}
if ( len >= sizeof( UIPAFtext ) - 1 ) {
trap->FS_Close( f );
Com_Error(ERR_DROP, "%s exceeds the allowed ui-side animation buffer!", filename);
}

trap->FS_Read( UIPAFtext, len, f );
UIPAFtext[len] = 0;
Expand Down Expand Up @@ -7125,8 +7124,11 @@ void UI_SetSiegeTeams(void)

len = trap->FS_Open(levelname, &f, FS_READ);

if (!f || len >= MAX_SIEGE_INFO_SIZE)
{
if (!f) {
return;
}
if (len >= MAX_SIEGE_INFO_SIZE) {
trap->FS_Close( f );
return;
}

Expand Down Expand Up @@ -9703,6 +9705,7 @@ static void UI_BuildPlayerModel_List( qboolean inGameLoad )
buffer = malloc(filelen + 1);
if(!buffer)
{
trap->FS_Close( f );
Com_Error(ERR_FATAL, "Could not allocate buffer to read %s", fpath);
}

Expand Down

0 comments on commit efbeb7c

Please sign in to comment.