fix -Warray-parameter, -Waddress, -Warray-bounds warnings

those are introduced by some compiler between gcc 10 and gcc 13
when using -Wall
This commit is contained in:
sbird 2023-10-15 10:56:55 +02:00 committed by Martin Griffin
parent 8ed29fb8e3
commit b77bc71862
16 changed files with 71 additions and 50 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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;

View file

@ -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)
{

View file

@ -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)

View file

@ -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];
}

View file

@ -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)

View file

@ -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);

View file

@ -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++);

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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++)