From f4ac8b198031402723dafea6353b76aa397311dc Mon Sep 17 00:00:00 2001 From: Regynate <64607261+Regynate@users.noreply.github.com> Date: Tue, 21 Jan 2025 20:59:47 +0300 Subject: [PATCH] DebugMenu: fixed comparator (#3695) Used to cause crashes on debug builds Also: [In C++, comparator should return false if its arguments are equal.](https://codeforces.com/blog/entry/70237) Co-authored-by: Reguas <64607261+Reguas@users.noreply.github.com> --- ChaosMod/Components/DebugMenu.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ChaosMod/Components/DebugMenu.cpp b/ChaosMod/Components/DebugMenu.cpp index 3b532c233..4e84fb3bf 100644 --- a/ChaosMod/Components/DebugMenu.cpp +++ b/ChaosMod/Components/DebugMenu.cpp @@ -36,12 +36,17 @@ DebugMenu::DebugMenu() : Component() [](const DebugEffect &a, const DebugEffect &b) { for (int idx = 0;; idx++) - if (idx >= a.EffectName.size() - || std::toupper(a.EffectName[idx]) < std::toupper(b.EffectName[idx])) - return true; - else if (idx >= b.EffectName.size() - || std::toupper(b.EffectName[idx]) < std::toupper(a.EffectName[idx])) + { + if (idx >= a.EffectName.size()) return false; + else if (idx >= b.EffectName.size()) + return true; + + auto ai = std::toupper(a.EffectName[idx]); + auto bi = std::toupper(b.EffectName[idx]); + if (ai != bi) + return ai < bi; + } }); }