From bf3622e8f16531d3fa45f15991ecd630a6657963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 5 Feb 2024 17:43:45 +0100 Subject: [PATCH] Fix and simplify check for maximum number of favorite communities Because of incorrect index/size math, two favorite communities were removed when exceeding the maximum number of three favorite communities instead of only one. The check can be simplified because the maximum number of favorite communities can never be exceeded, so at most the first element needs to be removed from the vector. Closes #7935. --- src/engine/client/serverbrowser.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 71c8f14f0..73d1e2f25 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -1701,13 +1701,14 @@ void CFavoriteCommunityFilterList::Add(const char *pCommunityId) // the end of the list, to allow setting the entire list easier with binds. Remove(pCommunityId); - // Ensure maximum number of favorite communities, by removing least-recently - // added communities from the beginning. One more than the maximum is removed - // to make room for the new community. + // Ensure maximum number of favorite communities, by removing the least-recently + // added community from the beginning, when the maximum number of favorite + // communities has been reached. constexpr size_t MaxFavoriteCommunities = 3; if(m_vEntries.size() >= MaxFavoriteCommunities) { - m_vEntries.erase(m_vEntries.begin(), m_vEntries.begin() + (MaxFavoriteCommunities - 1)); + dbg_assert(m_vEntries.size() == MaxFavoriteCommunities, "Maximum number of communities can never be exceeded"); + m_vEntries.erase(m_vEntries.begin()); } m_vEntries.emplace_back(pCommunityId); }