Don't use uninitialized ps from BotAI_GetClientState

If BotAI_GetPlayerState returns qfalse, ps is untouched and in
some cases means uninitialized. So don't use it if not valid.
This commit is contained in:
Zack Middleton 2017-06-07 19:02:01 -05:00
parent 74aa4268b2
commit 6e340f9a5b
4 changed files with 18 additions and 13 deletions

View file

@ -100,8 +100,7 @@ int BotIsFirstInRankings(bot_state_t *bs) {
//skip spectators //skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
// //
BotAI_GetClientState(i, &ps); if (BotAI_GetClientState(i, &ps) && score < ps.persistant[PERS_SCORE]) return qfalse;
if (score < ps.persistant[PERS_SCORE]) return qfalse;
} }
return qtrue; return qtrue;
} }
@ -124,8 +123,7 @@ int BotIsLastInRankings(bot_state_t *bs) {
//skip spectators //skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
// //
BotAI_GetClientState(i, &ps); if (BotAI_GetClientState(i, &ps) && score > ps.persistant[PERS_SCORE]) return qfalse;
if (score > ps.persistant[PERS_SCORE]) return qfalse;
} }
return qtrue; return qtrue;
} }
@ -150,8 +148,7 @@ char *BotFirstClientInRankings(void) {
//skip spectators //skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
// //
BotAI_GetClientState(i, &ps); if (BotAI_GetClientState(i, &ps) && ps.persistant[PERS_SCORE] > bestscore) {
if (ps.persistant[PERS_SCORE] > bestscore) {
bestscore = ps.persistant[PERS_SCORE]; bestscore = ps.persistant[PERS_SCORE];
bestclient = i; bestclient = i;
} }
@ -180,8 +177,7 @@ char *BotLastClientInRankings(void) {
//skip spectators //skip spectators
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue; if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
// //
BotAI_GetClientState(i, &ps); if (BotAI_GetClientState(i, &ps) && ps.persistant[PERS_SCORE] < worstscore) {
if (ps.persistant[PERS_SCORE] < worstscore) {
worstscore = ps.persistant[PERS_SCORE]; worstscore = ps.persistant[PERS_SCORE];
bestclient = i; bestclient = i;
} }

View file

@ -206,7 +206,10 @@ qboolean EntityIsDead(aas_entityinfo_t *entinfo) {
if (entinfo->number >= 0 && entinfo->number < MAX_CLIENTS) { if (entinfo->number >= 0 && entinfo->number < MAX_CLIENTS) {
//retrieve the current client state //retrieve the current client state
BotAI_GetClientState( entinfo->number, &ps ); if (!BotAI_GetClientState(entinfo->number, &ps)) {
return qfalse;
}
if (ps.pm_type != PM_NORMAL) return qtrue; if (ps.pm_type != PM_NORMAL) return qtrue;
} }
return qfalse; return qfalse;

View file

@ -990,8 +990,10 @@ int BotAI(int client, float thinktime) {
} }
//retrieve the current client state //retrieve the current client state
BotAI_GetClientState( client, &bs->cur_ps ); if (!BotAI_GetClientState(client, &bs->cur_ps)) {
BotAI_Print(PRT_FATAL, "BotAI: failed to get player state for player %d\n", client);
return qfalse;
}
//retrieve any waiting server commands //retrieve any waiting server commands
while( trap_BotGetServerCommand(client, buf, sizeof(buf)) ) { while( trap_BotGetServerCommand(client, buf, sizeof(buf)) ) {
//have buf point to the command and args to the command arguments //have buf point to the command and args to the command arguments

View file

@ -108,8 +108,12 @@ int BotClientTravelTimeToGoal(int client, bot_goal_t *goal) {
playerState_t ps; playerState_t ps;
int areanum; int areanum;
BotAI_GetClientState(client, &ps); if (BotAI_GetClientState(client, &ps)) {
areanum = BotPointAreaNum(ps.origin); areanum = BotPointAreaNum(ps.origin);
} else {
areanum = 0;
}
if (!areanum) return 1; if (!areanum) return 1;
return trap_AAS_AreaTravelTimeToGoalArea(areanum, ps.origin, goal->areanum, TFL_DEFAULT); return trap_AAS_AreaTravelTimeToGoalArea(areanum, ps.origin, goal->areanum, TFL_DEFAULT);
} }