From 6c08e1340661a118bbb376eeb3111610d1e306fa Mon Sep 17 00:00:00 2001 From: KylRikul <138259076+KylRikul@users.noreply.github.com> Date: Thu, 8 Oct 2026 12:10:29 +0200 Subject: [PATCH] Guard class power lookup against invalid resource indices - regression coverage --- tests/game/PowerIndexBounds.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/game/PowerIndexBounds.cpp diff --git a/tests/game/PowerIndexBounds.cpp b/tests/game/PowerIndexBounds.cpp new file mode 100644 index 0000000000..671c0b529d --- /dev/null +++ b/tests/game/PowerIndexBounds.cpp @@ -0,0 +1,16 @@ +#include "tc_catch2.h" +#include "DB2Stores.h" +#include + +TEST_CASE("Class power lookup rejects out of range resource identifiers", "[PowerIndexBounds]") +{ + for (uint32 classId : { uint32(CLASS_WARRIOR), uint32(CLASS_HUNTER), uint32(CLASS_PRIEST), uint32(CLASS_SHAMAN) }) + { + CAPTURE(classId); + // REQUIRE stops the unfixed lookup before the much larger invalid indices. + REQUIRE(DB2Manager::GetPowerIndexByClass(Powers(MAX_POWERS), classId) == MAX_POWERS_PER_CLASS); + CHECK(DB2Manager::GetPowerIndexByClass(Powers(MAX_POWERS + 1), classId) == MAX_POWERS_PER_CLASS); + CHECK(DB2Manager::GetPowerIndexByClass(Powers(-1), classId) == MAX_POWERS_PER_CLASS); + CHECK(DB2Manager::GetPowerIndexByClass(Powers(std::numeric_limits::max()), classId) == MAX_POWERS_PER_CLASS); + } +}