summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'games-arcade/project-starfighter/files/1.1-ammo.patch')
-rw-r--r--games-arcade/project-starfighter/files/1.1-ammo.patch53
1 files changed, 53 insertions, 0 deletions
diff --git a/games-arcade/project-starfighter/files/1.1-ammo.patch b/games-arcade/project-starfighter/files/1.1-ammo.patch
new file mode 100644
index 000000000000..c1b74c12c683
--- /dev/null
+++ b/games-arcade/project-starfighter/files/1.1-ammo.patch
@@ -0,0 +1,53 @@
+diff -ur orig/code/classes.h p1/code/classes.h
+--- orig/code/classes.h 2003-08-18 07:48:23.000000000 -0500
++++ p1/code/classes.h 2005-07-17 22:21:34.000000000 -0500
+@@ -91,6 +91,33 @@
+
+ public:
+
++ // Added July 2005 by Jason Bucata (jbucata@tulsaconnect.com)
++ // Needed to avoid type over/underflow in addition.
++ // I'm using references as that's more idiomatic C++
++ // (though I'm avoiding the temptation to try out templates here).
++
++ static void safeAdd(signed char& in, signed char add, int low, int high)
++ {
++ int temp = ((int)in) + ((int)add);
++ if (temp < low)
++ in = low;
++ else if (temp > high)
++ in = high;
++ else
++ in = temp;
++ }
++
++ static void safeAdd(unsigned char& in, unsigned char add, int low, int high)
++ {
++ int temp = ((int)in) + ((int)add);
++ if (temp < low)
++ in = low;
++ else if (temp > high)
++ in = high;
++ else
++ in = temp;
++ }
++
+ static void limitChar(signed char *in, int low, int high)
+ {
+ if (*in < low)
+diff -ur orig/code/collectable.cpp p1/code/collectable.cpp
+--- orig/code/collectable.cpp 2003-08-18 07:48:23.000000000 -0500
++++ p1/code/collectable.cpp 2005-07-17 22:24:18.000000000 -0500
+@@ -345,7 +345,11 @@
+ break;
+
+ case P_PLASMA_AMMO:
+- Math::limitChar(&(player.ammo[0] += collectable->value), 0, currentGame.maxPlasmaAmmo);
++ // Changed July 2005 by Jason Bucata (jbucata@tulsaconnect.com)
++ // Use safeAdd to avoid byte overflow in the add
++ // before it can be corrected by the applied limits.
++ //Math::limitChar(&(player.ammo[0] += collectable->value), 0, currentGame.maxPlasmaAmmo);
++ Math::safeAdd(player.ammo[0], collectable->value, 0, currentGame.maxPlasmaAmmo);
+ if (player.ammo[0] == currentGame.maxPlasmaAmmo)
+ sprintf(temp, "Plasma cells at Maximum");
+ else