shithub: choc

Download patch

ref: f6824b14fd2fcc81ad5e81d2655100ec0bb1af68
parent: a1f5d18c558d0db70913ca345f7a666347f658fc
parent: 3b1f3899c29aed3b767c2039541a9f51be9702a8
author: Turo Lamminen <turol@users.noreply.github.com>
date: Tue May 31 13:31:34 EDT 2022

Merge pull request #1461 from turol/fix-warning

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

--- 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;
 }