Add SAFE_DIV

This commit is contained in:
GriffinR
2021-03-19 18:17:43 -04:00
committed by huderlem
parent 28aff5b179
commit dfc6ee0e9e
6 changed files with 15 additions and 29 deletions

View File

@@ -3032,17 +3032,8 @@ static void SpriteCB_PokedexListMonSprite(struct Sprite *sprite)
else
{
u32 var;
sprite->pos2.y = gSineTable[(u8)sprite->data[5]] * 76 / 256;
// UB: possible division by zero
#ifdef UBFIX
if (gSineTable[sprite->data[5] + 64] != 0)
var = 0x10000 / gSineTable[sprite->data[5] + 64];
else
var = 0;
#else
var = 0x10000 / gSineTable[sprite->data[5] + 64];
#endif //UBFIX
var = SAFE_DIV(0x10000, gSineTable[sprite->data[5] + 64]);
if (var > 0xFFFF)
var = 0xFFFF;
SetOamMatrix(sprite->data[1] + 1, 0x100, 0, 0, var);