From e141cf74d5c6492db129f297faec432eccc4179a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 7 Sep 2008 22:17:12 +0000 Subject: [PATCH] Fixed three bugs with team natives that appeared on INS: bounds checking had wrong binary shortcut order, bounds checking was off by one, error condition was not returned properly. Out-of-range team indexes no longer cause crashes now. --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402523 --- extensions/sdktools/teamnatives.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extensions/sdktools/teamnatives.cpp b/extensions/sdktools/teamnatives.cpp index 33cc0134..b8df632e 100644 --- a/extensions/sdktools/teamnatives.cpp +++ b/extensions/sdktools/teamnatives.cpp @@ -112,9 +112,9 @@ static cell_t GetTeamCount(IPluginContext *pContext, const cell_t *params) static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) + if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName) { - pContext->ThrowNativeError("Team index %d is invalid", teamindex); + return pContext->ThrowNativeError("Team index %d is invalid", teamindex); } static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_szTeamname")->GetOffset(); @@ -128,9 +128,9 @@ static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params) static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) + if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName) { - pContext->ThrowNativeError("Team index %d is invalid", teamindex); + return pContext->ThrowNativeError("Team index %d is invalid", teamindex); } static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset(); @@ -141,9 +141,9 @@ static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params) static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) + if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName) { - pContext->ThrowNativeError("Team index %d is invalid", teamindex); + return pContext->ThrowNativeError("Team index %d is invalid", teamindex); } static int offset = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "m_iScore")->GetOffset(); @@ -155,9 +155,9 @@ static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params) static cell_t GetTeamClientCount(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) + if (teamindex >= (int)g_Teams.size() || !g_Teams[teamindex].ClassName) { - pContext->ThrowNativeError("Team index %d is invalid", teamindex); + return pContext->ThrowNativeError("Team index %d is invalid", teamindex); } SendProp *pProp = g_pGameHelpers->FindInSendTable(g_Teams[teamindex].ClassName, "\"player_array\"");