shithub: cstory

Download patch

ref: 12e4be58ac76d20577e6093449aded6236d5d188
parent: 10f389b52e2dde8811551dea522034df0d700fdc
parent: 81d672e1583e564a798f92c58ac4766af08503e4
author: Clownacy <[email protected]>
date: Mon Apr 6 09:55:58 EDT 2020

Merge pull request #101 from GabrielRavier/fixPortableBugs2

Fixed a bunch of npc->cond = 0 bugs

--- a/src/Bullet.cpp
+++ b/src/Bullet.cpp
@@ -1640,7 +1640,10 @@
 				bul->damage = 1;
 
 			if (bul->ani_no > 4)
+			{
 				bul->cond = 0;
+				return;	// Prevent UB at rc[bul->ani_no] when bul->ani_no == 5
+			}
 
 			break;
 	}
--- a/src/Caret.cpp
+++ b/src/Caret.cpp
@@ -73,7 +73,10 @@
 	{
 		crt->ani_wait = 0;
 		if (++crt->ani_no > 3)
+		{
 			crt->cond = 0;
+			return;	// Prevent UB at rc[crt->ani_no] when crt->ani_no == 4
+		}
 	}
 
 	// Note that 'crt->ani_no' can exceed the size of 'rcLeft' and 'rcRight'
@@ -247,7 +250,10 @@
 		crt->ani_wait = 0;
 
 		if (++crt->ani_no > 6)
+		{
 			crt->cond = 0;
+			return;	// Prevent UB at rcLeft[crt->ani_no] when crt->ani_no == 6
+		}
 	}
 
 	// Note that 'crt->ani_no' can exceed the size of rcLeft
@@ -453,7 +459,10 @@
 		crt->ani_wait = 0;
 
 		if (++crt->ani_no > 4)
+		{
 			crt->cond = 0;
+			return;	// Prevent UB at rect[crt->ani_no] when crt->ani_no == 5
+		}
 	}
 
 	// Note that 'crt->ani_no' can exceed the size of 'rect'
@@ -475,7 +484,10 @@
 		crt->ani_wait = 0;
 
 		if (++crt->ani_no > 3)
+		{
 			crt->cond = 0;
+			return;	// Prevent UB at rcLeft[crt->ani_no] when crt->ani_no == 4
+		}
 	}
 
 	// Note that 'crt->ani_no' can exceed the size of 'rcLeft'
--- a/src/NpcAct120.cpp
+++ b/src/NpcAct120.cpp
@@ -585,7 +585,10 @@
 	{
 		npc->ani_wait = 0;
 		if (++npc->ani_no > 2)
+		{
 			npc->cond = 0;
+			return; // Prevent UB at rc[npc->ani_no] when npc->ani_no == 3
+		}
 	}
 
 	// Note that 'npc->ani_no' can exceed the size of 'rcH' and 'rcV'
@@ -648,7 +651,10 @@
 	}
 
 	if (++npc->ani_no > 4)
+	{
 		npc->cond = 0;
+		return;	// Prevent UB at rc[npc->ani_no] when npc->ani_no == 5
+	}
 
 	// Note that 'npc->ani_no' can exceed the bounds of 'rcLeft', 'rcUp', 'rcRight' and 'rcDown'
 
@@ -701,7 +707,10 @@
 		npc->ani_wait = 0;
 
 		if (++npc->ani_no > 2)
+		{
 			npc->cond = 0;
+			return;	// Prevent UB at rect[(npc->direct * 3) + npc->ani_no] when npc->direct == 5 and npc->ani_no == 3
+		}
 	}
 
 	npc->y += npc->ym;
--- a/src/NpcAct140.cpp
+++ b/src/NpcAct140.cpp
@@ -753,6 +753,7 @@
 			{
 				SetDestroyNpChar(npc->x, npc->y, 0x1000, 8);
 				npc->cond = 0;
+				return;	// Prevent UB at rect[npc->ani_no] when npc->ani_no == 5
 			}
 
 			break;
--- a/src/NpcAct180.cpp
+++ b/src/NpcAct180.cpp
@@ -1426,7 +1426,10 @@
 	}
 
 	if (npc->ani_no > 4)
+	{
 		npc->cond = 0;
+		return;	// Prevent UB at rect[npc->ani_no] when npc->ani_no == 5
+	}
 
 	npc->x += npc->xm;
 	npc->y += npc->ym;