Fix duplicate bots displayed in Team Arena ingame add bot menu

The key handler allowed going 2 beyond the end of the bot list and the
display function clamped to 0 causing the first bot to be shown 3 times.

Attempting to add the bot in gametypes < GT_TEAM would fallback to
Sarge in UI_GetBotNameByNumber() (who isn't the first bot) and gametypes
>= GT_TEAM would access characterList past known values (typically NULL
but if teaminfo.txt contained 63 characters it would access out of
bounds memory).
This commit is contained in:
Zack Middleton 2018-05-06 01:39:20 -05:00
parent da861ff3a2
commit 10abac8fa0

View file

@ -1751,16 +1751,10 @@ static int UI_OwnerDrawWidth(int ownerDraw, float scale) {
static void UI_DrawBotName(rectDef_t *rect, float scale, vec4_t color, int textStyle) {
int value = uiInfo.botIndex;
int game = trap_Cvar_VariableValue("g_gametype");
const char *text = "";
const char *text;
if (game >= GT_TEAM) {
if (value >= uiInfo.characterCount) {
value = 0;
}
text = uiInfo.characterList[value].name;
} else {
if (value >= UI_GetNumBots()) {
value = 0;
}
text = UI_GetBotNameByNumber(value);
}
Text_Paint(rect->x, rect->y, scale, color, text, 0, 0, textStyle);
@ -2548,16 +2542,16 @@ static qboolean UI_BotName_HandleKey(int flags, float *special, int key) {
value += select;
if (game >= GT_TEAM) {
if (value >= uiInfo.characterCount + 2) {
if (value >= uiInfo.characterCount) {
value = 0;
} else if (value < 0) {
value = uiInfo.characterCount + 2 - 1;
value = uiInfo.characterCount - 1;
}
} else {
if (value >= UI_GetNumBots() + 2) {
if (value >= UI_GetNumBots()) {
value = 0;
} else if (value < 0) {
value = UI_GetNumBots() + 2 - 1;
value = UI_GetNumBots() - 1;
}
}
uiInfo.botIndex = value;