-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cmd_averagestats has UB #5000
Comments
luckytyphlosion pointed out their solution would not be compatible with agbcc. I suggest we wait with this one until it is fully deprecated and removed (#4994) |
If there is a solution it wouldn't be bad to fix on 1.8 |
for which release is agbcc's deprecation sheduled? we should do this fix in the same release |
it is being disabled in 1.9 but deprecated in 1.10. Though it would be a bugfix for 1.8.6 since this one is released at the same time 1.9 is |
A simple fix would be to write something like: u16 *GetBattlerStat(struct BattlePokemon *battler, u32 stat)
{
switch (stat)
{
case STAT_ATTACK: return &battler->attack;
case STAT_DEFENSE: return &battler->defense;
...
default: return NULL;
}
}
static void Cmd_averagestats(void)
{
CMD_ARGS(u8 stat);
u16 *stat1 = GetBattlerStat(&gBattleMons[gBattlerAttacker]), cmd->stat);
u16 *stat2 = GetBattlerStat(&gBattleMons[gBattlerTarget]), cmd->stat);
u16 avg = (*stat1 + *stat2) / 2;
*stat1 = *stat2 = avg;
gBattlescriptCurrInstr = cmd->nextInstr;
} |
Description
https://discord.com/channels/419213663107416084/774393519569502268/1263628135417774081
Version
master (default, unreleased bugfixes)
Upcoming/master Version
No response
Discord contact info
No response
The text was updated successfully, but these errors were encountered: