Merge pull request #99 from GabrielRavier/fixPortableBugs

Fix some UB
This commit is contained in:
Clownacy 2020-02-01 12:46:33 +00:00 committed by GitHub
commit debaeaad17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View file

@ -117,7 +117,10 @@ void ActCaret02(CARET *crt)
}
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 @@ void ActCaret02(CARET *crt)
}
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 @@ void ActCaret03(CARET *crt)
{
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 @@ void ActCaret05(CARET *crt)
++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 @@ void ActCaret11(CARET *crt)
{
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 @@ void ActCaret12(CARET *crt)
{
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];

View file

@ -271,6 +271,9 @@ void PutArmsEnergy(BOOL flash)
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];