foxygit / doom Log in
commit 61d285e851e099bbfc36a4f39e3d782fcebd0668
Author:     Turo Lamminen <turol@iki.fi>
AuthorDate: Thu Nov 17 14:54:55 2022 +0200
Commit:     Turo Lamminen <turol@users.noreply.github.com>
CommitDate: Sat Jan 27 17:34:21 2024 +0200

    doom: Add error checking in G_NextWeapon to silence cppcheck warning
---
 src/doom/g_game.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/doom/g_game.c b/src/doom/g_game.c
index f9a1d724..78bce280 100644
--- a/src/doom/g_game.c
+++ b/src/doom/g_game.c
@@ -305,6 +305,12 @@ static int G_NextWeapon(int direction)
         }
     }

+    // The current weapon must be present in weapon_order_table
+    // otherwise something has gone terribly wrong
+    if (i >= arrlen(weapon_order_table)) {
+        I_Error("Internal error: weapon %d not present in weapon_order_table", weapon);
+    }
+
     // Switch weapon. Don't loop forever.
     start_i = i;
     do