ref: debaeaad176706bf055fcf26934e6de5fa118194
parent: e3db7749baa82dba4ea4596b5df90301d6dd5a71
parent: 8042ab2c9b077e2ea630a9e99a9613834f2eaf73
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sat Feb 1 07:46:33 EST 2020
Merge pull request #99 from GabrielRavier/fixPortableBugs Fix some UB
--- a/src/Caret.cpp
+++ b/src/Caret.cpp
@@ -117,7 +117,10 @@
}
if (crt->ani_no > 3)
+ {
crt->cond = 0;
+ return; // Avoid unconditional UB at rect_left[crt->ani_no]
+ }
crt->rect = rect_left[crt->ani_no];
break;
@@ -130,7 +133,10 @@
}
if (crt->ani_no > 3)
+ {
crt->cond = 0;
+ return; // Avoid unconditional UB at rect_right[crt->ani_no]
+ }
crt->rect = rect_right[crt->ani_no];
break;
@@ -158,7 +164,10 @@
{
crt->ani_wait = 0;
if (++crt->ani_no > 3)
+ {
crt->cond = 0;
+ return; // Return now, or the access to rect[crt->ani_no] we do is UB
+ }
}
crt->rect = rect[crt->ani_no];
@@ -207,12 +216,15 @@
++crt->ani_no;
}
- if (crt->ani_no > 6)
- crt->cond = 0;
-
crt->x += 0x80;
crt->y -= 0x80;
+ if (crt->ani_no > 6)
+ {
+ crt->cond = 0;
+ return; // Return now, or the access to rect[crt->ani_no] we do is UB
+ }
+
crt->rect = rect[crt->ani_no];
}
@@ -349,7 +361,10 @@
{
crt->ani_wait = 0;
if (++crt->ani_no > 6)
+ {
crt->cond = 0;
+ return; // Avoid unconditional UB at rcRight[crt->ani_no]
+ }
}
crt->rect = rcRight[crt->ani_no];
@@ -366,7 +381,10 @@
{
crt->ani_wait = 0;
if (++crt->ani_no > 1)
+ {
crt->cond = 0;
+ return; // Return now, or the access to rcLeft[crt->ani_no] we do is UB
+ }
}
crt->rect = rcLeft[crt->ani_no];
--- a/src/MycParam.cpp
+++ b/src/MycParam.cpp
@@ -271,6 +271,9 @@
RECT rcExpFlash = {40, 80, 80, 88};
int lv = gArmsData[gSelectedArms].level - 1;
+ if (lv < 0) // Detect the case where the level is 0 (no weapon)
+ lv = 0; // Set lv to a safe value
+
int arms_code = gArmsData[gSelectedArms].code;
int exp_now = gArmsData[gSelectedArms].exp;
int exp_next = gArmsLevelTable[arms_code].exp[lv];
--
⑨