From 5e6fef409886efbac94897249694f6f245d5bb9a Mon Sep 17 00:00:00 2001 From: Roy Love Date: Fri, 10 Apr 2026 20:27:27 -0500 Subject: [PATCH] fix: correct off-by-one in GetSpellLevel for Berserker class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Class::Berserker == 16 and Class::PLAYER_CLASS_COUNT == 16, so the guard `class_id >= PLAYER_CLASS_COUNT` evaluated 16 >= 16 as true and returned UINT8_MAX before reaching the array lookup. The array access `classes[class_id - 1]` is correct — classes[15] is the valid Berserker slot. The bug was only in the boundary check. Replace the count-based guard with explicit named-constant bounds so the valid range (Warrior=1 through Berserker=16) is self-documenting and both ends are checked (class_id=0 would underflow the index). Fixes #5056 --- common/spdat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/spdat.cpp b/common/spdat.cpp index 1df6e55e5..3474e0d30 100644 --- a/common/spdat.cpp +++ b/common/spdat.cpp @@ -999,7 +999,7 @@ uint8 GetSpellLevel(uint16 spell_id, uint8 class_id) return UINT8_MAX; } - if (class_id >= Class::PLAYER_CLASS_COUNT) { + if (class_id < Class::Warrior || class_id > Class::Berserker) { return UINT8_MAX; }