Skip to content

Commit

Permalink
Fix/document possible division by zero in ConvertScaleParam
Browse files Browse the repository at this point in the history
  • Loading branch information
Sierraffinity committed Jan 5, 2021
1 parent b88922d commit 67a656a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion gflib/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,18 @@ void ApplyAffineAnimFrameRelativeAndUpdateMatrix(u8 matrixNum, struct AffineAnim

s16 ConvertScaleParam(s16 scale)
{
s16 ret;
s32 val = 0x10000;
return val / scale;
// UB: possible division by zero
#ifdef UBFIX
if (scale != 0)
ret = val / scale;
else
ret = 0;
#else
ret = val / scale;
#endif //UBFIX
return ret;
}

void GetAffineAnimFrame(u8 matrixNum, struct Sprite *sprite, struct AffineAnimFrameCmd *frameCmd)
Expand Down
2 changes: 1 addition & 1 deletion src/pokedex.c
Original file line number Diff line number Diff line change
Expand Up @@ -3042,7 +3042,7 @@ static void SpriteCB_PokedexListMonSprite(struct Sprite *sprite)
if (gSineTable[sprite->data[5] + 64] != 0)
var = 0x10000 / gSineTable[sprite->data[5] + 64];
else
var = 0xFFFF;
var = 0;
#else
var = 0x10000 / gSineTable[sprite->data[5] + 64];
#endif //UBFIX
Expand Down

0 comments on commit 67a656a

Please sign in to comment.