diff --git a/src/Bullet.cpp b/src/Bullet.cpp index c7157f85..9331717c 100644 --- a/src/Bullet.cpp +++ b/src/Bullet.cpp @@ -1640,7 +1640,10 @@ void ActBullet_Edge(BULLET *bul) 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; } diff --git a/src/Caret.cpp b/src/Caret.cpp index 308ac5a9..df9686b4 100644 --- a/src/Caret.cpp +++ b/src/Caret.cpp @@ -73,7 +73,10 @@ void ActCaret01(CARET *crt) { 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 @@ void ActCaret07(CARET *crt) 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 @@ void ActCaret14(CARET *crt) 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 @@ void ActCaret15(CARET *crt) 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' diff --git a/src/NpcAct120.cpp b/src/NpcAct120.cpp index 68e37bf5..c29ad5a1 100644 --- a/src/NpcAct120.cpp +++ b/src/NpcAct120.cpp @@ -585,7 +585,10 @@ void ActNpc127(NPCHAR *npc) { 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 @@ void ActNpc128(NPCHAR *npc) } 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 @@ void ActNpc129(NPCHAR *npc) 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; diff --git a/src/NpcAct140.cpp b/src/NpcAct140.cpp index f186a992..49986a29 100644 --- a/src/NpcAct140.cpp +++ b/src/NpcAct140.cpp @@ -753,6 +753,7 @@ void ActNpc146(NPCHAR *npc) { SetDestroyNpChar(npc->x, npc->y, 0x1000, 8); npc->cond = 0; + return; // Prevent UB at rect[npc->ani_no] when npc->ani_no == 5 } break; diff --git a/src/NpcAct180.cpp b/src/NpcAct180.cpp index 372b3563..98d90d26 100644 --- a/src/NpcAct180.cpp +++ b/src/NpcAct180.cpp @@ -1426,7 +1426,10 @@ void ActNpc199(NPCHAR *npc) } 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;