From 9f6cb92cb9610e2d5e556c84e280e767802d426d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 4 Aug 2024 21:27:08 +0200 Subject: [PATCH] Add assertions to `CBinds::Bind` and `Get` functions --- src/game/client/components/binds.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/game/client/components/binds.cpp b/src/game/client/components/binds.cpp index 90efe3269..e62d1d4c8 100644 --- a/src/game/client/components/binds.cpp +++ b/src/game/client/components/binds.cpp @@ -51,8 +51,8 @@ CBinds::~CBinds() void CBinds::Bind(int KeyId, const char *pStr, bool FreeOnly, int ModifierCombination) { - if(KeyId < 0 || KeyId >= KEY_LAST) - return; + dbg_assert(KeyId >= KEY_FIRST && KeyId < KEY_LAST, "KeyId invalid"); + dbg_assert(ModifierCombination >= MODIFIER_NONE && ModifierCombination < MODIFIER_COMBINATION_COUNT, "ModifierCombination invalid"); if(FreeOnly && Get(KeyId, ModifierCombination)[0]) return; @@ -189,9 +189,9 @@ void CBinds::UnbindAll() const char *CBinds::Get(int KeyId, int ModifierCombination) { - if(KeyId > 0 && KeyId < KEY_LAST && m_aapKeyBindings[ModifierCombination][KeyId]) - return m_aapKeyBindings[ModifierCombination][KeyId]; - return ""; + dbg_assert(KeyId >= KEY_FIRST && KeyId < KEY_LAST, "KeyId invalid"); + dbg_assert(ModifierCombination >= MODIFIER_NONE && ModifierCombination < MODIFIER_COMBINATION_COUNT, "ModifierCombination invalid"); + return m_aapKeyBindings[ModifierCombination][KeyId] ? m_aapKeyBindings[ModifierCombination][KeyId] : ""; } void CBinds::GetKey(const char *pBindStr, char *pBuf, size_t BufSize)