From b77bc718621b8a156b7fa42ad01316f0f0a25ccf Mon Sep 17 00:00:00 2001 From: sbird Date: Sun, 15 Oct 2023 10:56:55 +0200 Subject: [PATCH] fix -Warray-parameter, -Waddress, -Warray-bounds warnings those are introduced by some compiler between gcc 10 and gcc 13 when using -Wall --- gflib/bg.c | 3 +++ include/battle_main.h | 2 +- include/battle_util.h | 2 +- include/util.h | 2 +- src/battle_anim_utility_funcs.c | 8 ++++---- src/battle_dome.c | 2 +- src/battle_intro.c | 22 ++++++++++------------ src/battle_main.c | 6 ++++-- src/battle_script_commands.c | 28 +++++++++++++++++++++------- src/battle_util.c | 8 +++++--- src/contest.c | 12 ++++++------ src/field_specials.c | 2 ++ src/field_weather.c | 12 ++++++------ src/librfu_rfu.c | 2 +- src/tv.c | 8 ++++---- src/util.c | 2 +- 16 files changed, 71 insertions(+), 50 deletions(-) diff --git a/gflib/bg.c b/gflib/bg.c index f363233a85..4e426b762b 100644 --- a/gflib/bg.c +++ b/gflib/bg.c @@ -377,6 +377,9 @@ u16 LoadBgTiles(u8 bg, const void *src, u16 size, u16 destOffset) u16 tileOffset; u8 cursor; + if (bg > 3) + return -1; + if (GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE) == 0) { tileOffset = (sGpuBgConfigs2[bg].baseTile + destOffset) * 0x20; diff --git a/include/battle_main.h b/include/battle_main.h index 91e9fd90eb..9bb9bbdfb0 100644 --- a/include/battle_main.h +++ b/include/battle_main.h @@ -54,7 +54,7 @@ void AnimSetCenterToCornerVecX(struct Sprite *sprite); void BeginBattleIntroDummy(void); void BeginBattleIntro(void); void SwitchInClearSetData(u32 battler); -void FaintClearSetData(u32 battler); +const u8* FaintClearSetData(u32 battler); void BattleTurnPassed(void); u8 IsRunningFromBattleImpossible(u32 battler); void SwitchPartyOrder(u32 battlerId); diff --git a/include/battle_util.h b/include/battle_util.h index ec7fa42800..02c5afa7a3 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -121,7 +121,7 @@ void PressurePPLoseOnUsingImprison(u8 attacker); bool32 IsBattlerMarkedForControllerExec(u32 battler); void MarkBattlerForControllerExec(u32 battler); void MarkBattlerReceivedLinkData(u32 battler); -void CancelMultiTurnMoves(u32 battler); +const u8* CancelMultiTurnMoves(u32 battler); bool32 WasUnableToUseMove(u32 battler); void PrepareStringBattle(u16 stringId, u32 battler); void ResetSentPokesToOpponentValue(void); diff --git a/include/util.h b/include/util.h index 8f2079a0ba..3c90f136a6 100644 --- a/include/util.h +++ b/include/util.h @@ -13,7 +13,7 @@ int CountTrailingZeroBits(u32 value); u16 CalcCRC16(const u8 *data, s32 length); u16 CalcCRC16WithTable(const u8 *data, u32 length); u32 CalcByteArraySum(const u8 *data, u32 length); -void BlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor); +void BlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u32 blendColor); void DoBgAffineSet(struct BgAffineDstData *dest, u32 texX, u32 texY, s16 scrX, s16 scrY, s16 sx, s16 sy, u16 alpha); void CopySpriteTiles(u8 shape, u8 size, u8 *tiles, u16 *tilemap, u8 *output); diff --git a/src/battle_anim_utility_funcs.c b/src/battle_anim_utility_funcs.c index 99e476da1d..491ca77a96 100644 --- a/src/battle_anim_utility_funcs.c +++ b/src/battle_anim_utility_funcs.c @@ -281,7 +281,7 @@ void AnimTask_DrawFallingWhiteLinesOnAttacker(u8 taskId) u16 species; int spriteId, newSpriteId; u16 var0; - u16 bg1Cnt; + u32 bg1Cnt; struct BattleAnimBgData animBgData; var0 = 0; @@ -350,7 +350,7 @@ static void AnimTask_DrawFallingWhiteLinesOnAttacker_Step(u8 taskId) { struct BattleAnimBgData animBgData; struct Sprite *sprite; - u16 bg1Cnt; + u32 bg1Cnt; gTasks[taskId].data[10] += 4; gBattle_BG1_Y -= 4; @@ -814,7 +814,7 @@ void StartMonScrollingBgMask(u8 taskId, int UNUSED unused, u16 scrollSpeed, u8 b { u16 species; u8 spriteId, spriteId2; - u16 bg1Cnt; + u32 bg1Cnt; struct BattleAnimBgData animBgData; u8 battler2; @@ -919,7 +919,7 @@ static void UpdateMonScrollingBgMask(u8 taskId) | WINOUT_WINOBJ_BG_ALL | WINOUT_WINOBJ_OBJ | WINOUT_WINOBJ_CLR); if (!IsContest()) { - u16 bg1Cnt = GetGpuReg(REG_OFFSET_BG1CNT); + u32 bg1Cnt = GetGpuReg(REG_OFFSET_BG1CNT); ((vBgCnt *)&bg1Cnt)->charBaseBlock = 0; SetGpuReg(REG_OFFSET_BG1CNT, bg1Cnt); } diff --git a/src/battle_dome.c b/src/battle_dome.c index 313d7289d9..24bad30f6b 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -6016,7 +6016,7 @@ static void DecideRoundWinners(u8 roundId) gSaveBlock2Ptr->frontier.domeWinningMoves[tournamentId2] = GetWinningMove(tournamentId1, tournamentId2, roundId); } // Frontier Brain always wins, check tournamentId2. - else if (DOME_TRAINERS[tournamentId2].trainerId == TRAINER_FRONTIER_BRAIN && tournamentId1 != 0xFF) + else if (tournamentId2 != 0xFF && DOME_TRAINERS[tournamentId2].trainerId == TRAINER_FRONTIER_BRAIN && tournamentId1 != 0xFF) { DOME_TRAINERS[tournamentId1].isEliminated = TRUE; DOME_TRAINERS[tournamentId1].eliminatedAt = roundId; diff --git a/src/battle_intro.c b/src/battle_intro.c index 11e07bab73..ac88f570db 100644 --- a/src/battle_intro.c +++ b/src/battle_intro.c @@ -11,8 +11,6 @@ #include "trig.h" #include "constants/trainers.h" -static EWRAM_DATA u16 sBgCnt = 0; - extern const u8 gBattleAnimBgCntSet[]; extern const u8 gBattleAnimBgCntGet[]; @@ -40,39 +38,39 @@ void SetAnimBgAttribute(u8 bgId, u8 attributeId, u8 value) { if (bgId < 4) { - sBgCnt = GetGpuReg(gBattleAnimBgCntSet[bgId]); + u32 bgCnt = GetGpuReg(gBattleAnimBgCntSet[bgId]); switch (attributeId) { case BG_ANIM_SCREEN_SIZE: - ((struct BgCnt *)&sBgCnt)->screenSize = value; + ((struct BgCnt *)&bgCnt)->screenSize = value; break; case BG_ANIM_AREA_OVERFLOW_MODE: - ((struct BgCnt *)&sBgCnt)->areaOverflowMode = value; + ((struct BgCnt *)&bgCnt)->areaOverflowMode = value; break; case BG_ANIM_MOSAIC: - ((struct BgCnt *)&sBgCnt)->mosaic = value; + ((struct BgCnt *)&bgCnt)->mosaic = value; break; case BG_ANIM_CHAR_BASE_BLOCK: - ((struct BgCnt *)&sBgCnt)->charBaseBlock = value; + ((struct BgCnt *)&bgCnt)->charBaseBlock = value; break; case BG_ANIM_PRIORITY: - ((struct BgCnt *)&sBgCnt)->priority = value; + ((struct BgCnt *)&bgCnt)->priority = value; break; case BG_ANIM_PALETTES_MODE: - ((struct BgCnt *)&sBgCnt)->palettes = value; + ((struct BgCnt *)&bgCnt)->palettes = value; break; case BG_ANIM_SCREEN_BASE_BLOCK: - ((struct BgCnt *)&sBgCnt)->screenBaseBlock = value; + ((struct BgCnt *)&bgCnt)->screenBaseBlock = value; break; } - SetGpuReg(gBattleAnimBgCntSet[bgId], sBgCnt); + SetGpuReg(gBattleAnimBgCntSet[bgId], bgCnt); } } int GetAnimBgAttribute(u8 bgId, u8 attributeId) { - u16 bgCnt; + u32 bgCnt; if (bgId < 4) { diff --git a/src/battle_main.c b/src/battle_main.c index 325d66eb23..18de8e3b1f 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3220,9 +3220,10 @@ void SwitchInClearSetData(u32 battler) Ai_UpdateSwitchInData(battler); } -void FaintClearSetData(u32 battler) +const u8* FaintClearSetData(u32 battler) { s32 i; + const u8 *result = NULL; for (i = 0; i < NUM_BATTLE_STATS; i++) gBattleMons[battler].statStages[i] = DEFAULT_STAT_STAGE; @@ -3356,7 +3357,7 @@ void FaintClearSetData(u32 battler) { gBattleMons[otherSkyDropper].status2 |= STATUS2_CONFUSION_TURN(((Random()) % 4) + 2); gBattlerAttacker = otherSkyDropper; - gBattlescriptCurrInstr = BattleScript_ThrashConfuses - 2; + result = BattleScript_ThrashConfuses; } } } @@ -3366,6 +3367,7 @@ void FaintClearSetData(u32 battler) gBattleStruct->zmove.active = FALSE; gBattleStruct->zmove.toBeUsed[battler] = MOVE_NONE; gBattleStruct->zmove.effect = EFFECT_HIT; + return result; } static void DoBattleIntro(void) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 0c42bedbb9..d9f1e04ff9 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -2793,6 +2793,7 @@ void SetMoveEffect(bool32 primary, u32 certain) if (gBattleScripting.moveEffect <= PRIMARY_STATUS_MOVE_EFFECT) // status change { + const u8 *cancelMultiTurnMovesResult = NULL; switch (sStatusFlagsForMoveEffects[gBattleScripting.moveEffect]) { case STATUS1_SLEEP: @@ -2812,7 +2813,9 @@ void SetMoveEffect(bool32 primary, u32 certain) if (!CanSleep(gEffectBattler)) break; - CancelMultiTurnMoves(gEffectBattler); + cancelMultiTurnMovesResult = CancelMultiTurnMoves(gEffectBattler); + if (cancelMultiTurnMovesResult) + gBattlescriptCurrInstr = cancelMultiTurnMovesResult; statusChanged = TRUE; break; case STATUS1_POISON: @@ -2894,7 +2897,9 @@ void SetMoveEffect(bool32 primary, u32 certain) if (!CanBeFrozen(gEffectBattler)) break; - CancelMultiTurnMoves(gEffectBattler); + cancelMultiTurnMovesResult = CancelMultiTurnMoves(gEffectBattler); + if (cancelMultiTurnMovesResult) + gBattlescriptCurrInstr = cancelMultiTurnMovesResult; statusChanged = TRUE; break; case STATUS1_PARALYSIS: @@ -3823,7 +3828,7 @@ static void Cmd_cleareffectsonfaint(void) if (gBattleControllerExecFlags == 0) { u32 battler = GetBattlerForBattleScript(cmd->battler); - + const u8 *clearDataResult = NULL; if (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || gBattleMons[battler].hp == 0) { gBattleMons[battler].status1 = 0; @@ -3831,8 +3836,11 @@ static void Cmd_cleareffectsonfaint(void) MarkBattlerForControllerExec(battler); } - FaintClearSetData(battler); // Effects like attractions, trapping, etc. - gBattlescriptCurrInstr = cmd->nextInstr; + clearDataResult = FaintClearSetData(battler); // Effects like attractions, trapping, etc. + if (clearDataResult) + gBattlescriptCurrInstr = clearDataResult; + else + gBattlescriptCurrInstr = cmd->nextInstr; } } @@ -8741,7 +8749,13 @@ static void Cmd_various(void) case VARIOUS_CANCEL_MULTI_TURN_MOVES: { VARIOUS_ARGS(); - CancelMultiTurnMoves(battler); + const u8 *result; + result = CancelMultiTurnMoves(battler); + if (result) + { + gBattlescriptCurrInstr = result; + return; + } break; } case VARIOUS_SET_MAGIC_COAT_TARGET: @@ -13724,7 +13738,7 @@ u16 GetNaturePowerMove(void) return MOVE_ENERGY_BALL; else if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN) return MOVE_PSYCHIC; - else if (sNaturePowerMoves == MOVE_NONE) + else if (sNaturePowerMoves[gBattleTerrain] == MOVE_NONE) return MOVE_TRI_ATTACK; return sNaturePowerMoves[gBattleTerrain]; } diff --git a/src/battle_util.c b/src/battle_util.c index 5429788d23..fa11937285 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1333,8 +1333,9 @@ void MarkBattlerReceivedLinkData(u32 battler) gBattleControllerExecFlags &= ~((1 << 28) << battler); } -void CancelMultiTurnMoves(u32 battler) +const u8* CancelMultiTurnMoves(u32 battler) { + const u8 *result = NULL; gBattleMons[battler].status2 &= ~(STATUS2_MULTIPLETURNS); gBattleMons[battler].status2 &= ~(STATUS2_LOCK_CONFUSE); gBattleMons[battler].status2 &= ~(STATUS2_UPROAR); @@ -1389,14 +1390,14 @@ void CancelMultiTurnMoves(u32 battler) else if (gBattlescriptCurrInstr[0] == 0x76 && gBattlescriptCurrInstr[2] == 0) { gBattlerAttacker = otherSkyDropper; - gBattlescriptCurrInstr = BattleScript_ThrashConfuses - 3; + result = BattleScript_ThrashConfuses; } // If this CancelMultiTurnMoves is occuring due to receiving Sleep/Freeze status else if (gBattleScripting.moveEffect <= PRIMARY_STATUS_MOVE_EFFECT) { gBattlerAttacker = otherSkyDropper; BattleScriptPush(gBattlescriptCurrInstr + 1); - gBattlescriptCurrInstr = BattleScript_ThrashConfuses - 1; + result = BattleScript_ThrashConfuses; } } } @@ -1411,6 +1412,7 @@ void CancelMultiTurnMoves(u32 battler) gDisableStructs[battler].rolloutTimer = 0; gDisableStructs[battler].furyCutterCounter = 0; + return result; } bool32 WasUnableToUseMove(u32 battler) diff --git a/src/contest.c b/src/contest.c index 7b29b55908..8f452b0921 100644 --- a/src/contest.c +++ b/src/contest.c @@ -1409,8 +1409,8 @@ static void Task_RaiseCurtainAtStart(u8 taskId) break; case 3: { - u16 bg0Cnt = GetGpuReg(REG_OFFSET_BG0CNT); - u16 bg2Cnt = GetGpuReg(REG_OFFSET_BG2CNT); + u32 bg0Cnt = GetGpuReg(REG_OFFSET_BG0CNT); + u32 bg2Cnt = GetGpuReg(REG_OFFSET_BG2CNT); ((struct BgCnt *)&bg0Cnt)->priority = 0; ((struct BgCnt *)&bg2Cnt)->priority = 0; SetGpuReg(REG_OFFSET_BG0CNT, bg0Cnt); @@ -2630,8 +2630,8 @@ static void Task_UpdateContestantBoxOrder(u8 taskId) static void Task_TryStartNextRoundOfAppeals(u8 taskId) { - vu16 sp0 = GetGpuReg(REG_OFFSET_BG0CNT); - vu16 sp2 = GetGpuReg(REG_OFFSET_BG2CNT); + vu32 sp0 = GetGpuReg(REG_OFFSET_BG0CNT); + vu32 sp2 = GetGpuReg(REG_OFFSET_BG2CNT); ((vBgCnt *)&sp0)->priority = 0; ((vBgCnt *)&sp2)->priority = 0; SetGpuReg(REG_OFFSET_BG0CNT, sp0); @@ -5055,7 +5055,7 @@ bool8 IsContestantAllowedToCombo(u8 contestant) static void SetBgForCurtainDrop(void) { s32 i; - u16 bg0Cnt, bg1Cnt, bg2Cnt; + u32 bg0Cnt, bg1Cnt, bg2Cnt; bg1Cnt = GetGpuReg(REG_OFFSET_BG1CNT); ((vBgCnt *)&bg1Cnt)->priority = 0; @@ -5093,7 +5093,7 @@ static void SetBgForCurtainDrop(void) static void UpdateContestantBoxOrder(void) { s32 i; - u16 bg1Cnt; + u32 bg1Cnt; RequestDma3Fill(0,(void *)(BG_CHAR_ADDR(2)), 0x2000, 1); CpuFill32(0, gContestResources->contestBgTilemaps[1], 0x1000); diff --git a/src/field_specials.c b/src/field_specials.c index 2720e5f587..13b8ae9daf 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -2201,6 +2201,8 @@ void ShowFrontierManiacMessage(void) else winStreak = gSaveBlock2Ptr->frontier.pyramidWinStreaks[FRONTIER_LVL_OPEN]; break; + default: + return; } for (i = 0; i < FRONTIER_MANIAC_MESSAGE_COUNT - 1 && sFrontierManiacStreakThresholds[facility][i] < winStreak; i++); diff --git a/src/field_weather.c b/src/field_weather.c index 80f32a14ca..0f0b137d9a 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -47,9 +47,9 @@ static bool8 LightenSpritePaletteInFog(u8); static void BuildColorMaps(void); static void UpdateWeatherColorMap(void); static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex); -static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u16 blendColor); -static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 blendColor); -static void ApplyFogBlend(u8 blendCoeff, u16 blendColor); +static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u32 blendColor); +static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u32 blendColor); +static void ApplyFogBlend(u8 blendCoeff, u32 blendColor); static bool8 FadeInScreen_RainShowShade(void); static bool8 FadeInScreen_Drought(void); static bool8 FadeInScreen_FogHorizontal(void); @@ -544,7 +544,7 @@ static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex) } } -static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u16 blendColor) +static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex, u8 blendCoeff, u32 blendColor) { u16 palOffset; u16 curPalIndex; @@ -595,7 +595,7 @@ static void ApplyColorMapWithBlend(u8 startPalIndex, u8 numPalettes, s8 colorMap } } -static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 blendColor) +static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u32 blendColor) { struct RGBColor color; u8 rBlend; @@ -650,7 +650,7 @@ static void ApplyDroughtColorMapWithBlend(s8 colorMapIndex, u8 blendCoeff, u16 b } } -static void ApplyFogBlend(u8 blendCoeff, u16 blendColor) +static void ApplyFogBlend(u8 blendCoeff, u32 blendColor) { struct RGBColor color; u8 rBlend; diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 2dbd404616..152bb716e9 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -1409,7 +1409,7 @@ static u16 rfu_STC_setSendData_org(u8 ni_or_uni, u8 bmSendSlot, u8 subFrameSize, struct RfuSlotStatusUNI *slotStatus_UNI; struct RfuSlotStatusNI *slotStatus_NI; - if (gRfuLinkStatus->parentChild == MODE_NEUTRAL) + if (gRfuLinkStatus->parentChild > MODE_PARENT) return ERR_MODE_NOT_CONNECTED; if (!(bmSendSlot & 0xF)) return ERR_SLOT_NO; diff --git a/src/tv.c b/src/tv.c index d39464bcc0..306d0fc9e3 100644 --- a/src/tv.c +++ b/src/tv.c @@ -107,22 +107,22 @@ static bool8 IsAddingPokeNewsDisallowed(u8); static void ClearPokeNewsBySlot(u8); static void TranslateRubyShows(TVShow *); static void TranslateJapaneseEmeraldShows(TVShow *); -static void SetMixedTVShows(TVShow *, TVShow *, TVShow *, TVShow *); +static void SetMixedTVShows(TVShow[TV_SHOWS_COUNT], TVShow[TV_SHOWS_COUNT], TVShow[TV_SHOWS_COUNT], TVShow[TV_SHOWS_COUNT]); static void DeleteExcessMixedShows(void); static void DeactivateShowsWithUnseenSpecies(void); static void DeactivateGameCompleteShowsIfNotUnlocked(void); static s8 FindInactiveShowInArray(TVShow *); -static bool8 TryMixTVShow(TVShow *[], TVShow *[], u8); +static bool8 TryMixTVShow(TVShow *[TV_SHOWS_COUNT], TVShow *[TV_SHOWS_COUNT], u8); static bool8 TryMixNormalTVShow(TVShow *, TVShow *, u8); static bool8 TryMixRecordMixTVShow(TVShow *, TVShow *, u8); static bool8 TryMixOutbreakTVShow(TVShow *, TVShow *, u8); static void DeactivateShow(u8 showIdx); static void DeactivateShowIfNotSeenSpecies(u16, u8); -static void SetMixedPokeNews(PokeNews *, PokeNews *, PokeNews *, PokeNews *); +static void SetMixedPokeNews(PokeNews[POKE_NEWS_COUNT], PokeNews[POKE_NEWS_COUNT], PokeNews[POKE_NEWS_COUNT], PokeNews[POKE_NEWS_COUNT]); static void ClearInvalidPokeNews(void); static void ClearPokeNewsIfGameNotComplete(void); static s8 GetPokeNewsSlotIfActive(PokeNews *, u8); -static void InitTryMixPokeNewsShow(PokeNews *[], PokeNews *[]); +static void InitTryMixPokeNewsShow(PokeNews *[POKE_NEWS_COUNT], PokeNews *[POKE_NEWS_COUNT]); static bool8 TryMixPokeNewsShow(PokeNews *, PokeNews *, s8); static void TVShowDone(void); static void InterviewAfter_FanClubLetter(void); diff --git a/src/util.c b/src/util.c index 09381fcaf3..77d9cde2f1 100644 --- a/src/util.c +++ b/src/util.c @@ -261,7 +261,7 @@ u32 CalcByteArraySum(const u8 *data, u32 length) return sum; } -void BlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) +void BlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u32 blendColor) { u16 i; for (i = 0; i < numEntries; i++)