From db7dc509e0dbdec48f15eeb4b69f685a4a816513 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 21 Nov 2006 23:59:21 +0000 Subject: [PATCH] Fixed another serious bug where deleting menus and not returning PLUGIN_HANDLED would cause the iterator to fail and crash --- amxmodx/CMenu.cpp | 13 +++++++++++++ amxmodx/CMenu.h | 9 ++++++++- amxmodx/amxmodx.h | 2 +- amxmodx/meta_api.cpp | 10 +++++++++- amxmodx/msvc8/amxmodx_mm.vcproj | 4 ---- amxmodx/version.rc | 8 ++++---- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/amxmodx/CMenu.cpp b/amxmodx/CMenu.cpp index 17a7afb9..69fc254e 100755 --- a/amxmodx/CMenu.cpp +++ b/amxmodx/CMenu.cpp @@ -87,6 +87,10 @@ void MenuMngr::removeMenuId(int id) { if (c->menuid == id) { + if (m_watch_iter.a == c) + { + ++m_watch_iter; + } if (lc) lc->next = c->next; else @@ -140,4 +144,13 @@ void MenuMngr::clear() } } +MenuMngr::iterator MenuMngr::SetWatchIter(MenuMngr::iterator iter) +{ + MenuMngr::iterator old = m_watch_iter; + + m_watch_iter = iter; + + return old; +} + int MenuMngr::MenuIdEle::uniqueid = 0; diff --git a/amxmodx/CMenu.h b/amxmodx/CMenu.h index 902e670c..ca27325c 100755 --- a/amxmodx/CMenu.h +++ b/amxmodx/CMenu.h @@ -76,7 +76,8 @@ private: } *headcmd; public: - MenuMngr() { headid = 0; headcmd = 0; } + MenuMngr() : m_watch_iter(end()) + { headid = NULL; headcmd = NULL; } ~MenuMngr(); // Interface @@ -89,6 +90,7 @@ public: class iterator { + friend class MenuMngr; MenuCommand* a; public: iterator(MenuCommand*aa) : a(aa) {} @@ -101,6 +103,11 @@ public: inline iterator begin() const { return iterator(headcmd); } inline iterator end() const { return iterator(0); } + + MenuMngr::iterator SetWatchIter(MenuMngr::iterator iter); + inline MenuMngr::iterator GetWatchIter() { return m_watch_iter; } +private: + MenuMngr::iterator m_watch_iter; }; #endif //MENUS_H diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index aa726e83..a49cf639 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -73,7 +73,7 @@ #define AMXXLOG_Log g_log.Log #define AMXXLOG_Error g_log.LogError -#define AMX_VERSION "1.76b" +#define AMX_VERSION "1.76c" extern AMX_NATIVE_INFO core_Natives[]; extern AMX_NATIVE_INFO time_Natives[]; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 55232ed3..c216084e 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -901,6 +901,7 @@ void C_ClientCommand(edict_t *pEntity) pPlayer->menu = 0; MenuMngr::iterator a = g_menucmds.begin(); + MenuMngr::iterator old = g_menucmds.SetWatchIter(a); while (a) { @@ -940,8 +941,15 @@ void C_ClientCommand(edict_t *pEntity) if (ret & 1) RETURN_META(MRES_SUPERCEDE); } } - ++a; + if (g_menucmds.GetWatchIter() != a) + { + a = g_menucmds.GetWatchIter(); + } else { + ++a; + } } + + g_menucmds.SetWatchIter(old); } } diff --git a/amxmodx/msvc8/amxmodx_mm.vcproj b/amxmodx/msvc8/amxmodx_mm.vcproj index 7ed66d5c..3451043c 100644 --- a/amxmodx/msvc8/amxmodx_mm.vcproj +++ b/amxmodx/msvc8/amxmodx_mm.vcproj @@ -778,10 +778,6 @@ RelativePath="..\md5.h" > - - diff --git a/amxmodx/version.rc b/amxmodx/version.rc index 61820143..6c588531 100755 --- a/amxmodx/version.rc +++ b/amxmodx/version.rc @@ -27,8 +27,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,7,6,2 - PRODUCTVERSION 1,7,6,2 + FILEVERSION 1,7,6,3 + PRODUCTVERSION 1,7,6,3 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -45,12 +45,12 @@ BEGIN BEGIN VALUE "Comments", "AMX Mod X" VALUE "FileDescription", "AMX Mod X" - VALUE "FileVersion", "1.76b" + VALUE "FileVersion", "1.76c" VALUE "InternalName", "amxmodx" VALUE "LegalCopyright", "Copyright (c) 2004-2006, AMX Mod X Dev Team" VALUE "OriginalFilename", "amxmodx_mm.dll" VALUE "ProductName", "AMX Mod X" - VALUE "ProductVersion", "1.76b" + VALUE "ProductVersion", "1.76c" END END BLOCK "VarFileInfo"