shithub: choc

Download patch

ref: 3b1f3899c29aed3b767c2039541a9f51be9702a8
parent: a7cd250da15ee76d0d6cf485a4488b40703982e8
author: Turo Lamminen <turol@iki.fi>
date: Thu Apr 28 13:30:42 EDT 2022

strife: Fix "array subscript is above array bounds" warning

Refactor an if ladder into a switch and then explicitly ignore
NUMPOWERS value which should never happen.

--- a/src/strife/p_inter.c
+++ b/src/strife/p_inter.c
@@ -354,7 +354,8 @@
         return false;
 
     // villsa [STRIFE]
-    if(power == pw_targeter)
+    switch (power) {
+    case pw_targeter:
     {
         player->powers[power] = TARGTICS;
         P_SetPsprite(player, ps_targcenter, S_TRGT_00); // 10
@@ -368,7 +369,7 @@
         return true;
     }
 
-    if(power == pw_invisibility)
+    case pw_invisibility:
     {
         // if player already had this power...
         if(player->powers[power])
@@ -386,13 +387,13 @@
         return true;
     }
 
-    if(power == pw_ironfeet)
+    case pw_ironfeet:
     {
         player->powers[power] = IRONTICS;
         return true;
     }
 
-    if(power == pw_strength)
+    case pw_strength:
     {
         P_GiveBody(player, 100);
         player->powers[power] = 1;
@@ -400,7 +401,7 @@
     }
 
     // villsa [STRIFE]
-    if(power == pw_allmap)
+    case pw_allmap:
     {
         // remember in mapstate
         if(gamemap < 40)
@@ -411,14 +412,17 @@
     }
 
     // villsa [STRIFE]
-    if(power == pw_communicator)
+    case pw_communicator:
     {
         player->powers[power] = 1;
         return true;
     }
 
-    // default behavior:
-    player->powers[power] = 1;
+    case NUMPOWERS:
+        // This should never actually happen
+        break;
+    }
+
     return true;
 }