From d419a25be33193058347290d01eeffbf7ad57715 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Sat, 22 Jun 2024 09:57:16 -0400 Subject: [PATCH] Use ARRAY_SIZE macro in asserts, fix ARRAY_SIZE macro to match --- include/global.h | 2 +- src/c/c_dylink.cpp | 6 +++--- src/d/d_s_play.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/global.h b/include/global.h index a0eb85035..752bcc4da 100644 --- a/include/global.h +++ b/include/global.h @@ -3,7 +3,7 @@ #include "dolphin/types.h" -#define ARRAY_SIZE(o) (sizeof((o)) / sizeof(*(o))) +#define ARRAY_SIZE(o) (sizeof(o) / sizeof(o[0])) // Align X to the previous N bytes (N must be power of two) #define ALIGN_PREV(X, N) ((X) & ~((N)-1)) diff --git a/src/c/c_dylink.cpp b/src/c/c_dylink.cpp index 76243b866..f39e7d154 100644 --- a/src/c/c_dylink.cpp +++ b/src/c/c_dylink.cpp @@ -469,7 +469,7 @@ s32 cCc_Init() { if (d.name == NULL) continue; - JUT_ASSERT(0x39, d.mKey < (sizeof(DMC) / sizeof(DMC[0]))); + JUT_ASSERT(0x39, d.mKey < ARRAY_SIZE(DMC)); JUT_ASSERT(0x3a, DMC[d.mKey] == 0); for (int j = 0; j < ARRAY_SIZE(DMC); j++) { @@ -504,7 +504,7 @@ s32 cDyl_IsLinked(s16 i_ProfName) { /* 80022A80-80022B58 .text cDyl_Unlink__Fs */ s32 cDyl_Unlink(s16 i_ProfName) { JUT_ASSERT(0xc5, cDyl_Initialized); - JUT_ASSERT(0xc6, i_ProfName < (sizeof(DMC) / sizeof(DMC[0]))); + JUT_ASSERT(0xc6, i_ProfName < ARRAY_SIZE(DMC)); if (DMC[i_ProfName] != NULL) return DMC[i_ProfName]->unlink(); @@ -529,7 +529,7 @@ s32 cDyl_LinkASync(s16 i_ProfName) { return cPhs_ERROR_e; } - JUT_ASSERT(0x111, i_ProfName < (sizeof(DMC) / sizeof(DMC[0]))); + JUT_ASSERT(0x111, i_ProfName < ARRAY_SIZE(DMC)); DynamicModuleControlBase * d = DMC[i_ProfName]; if (d != NULL) { JUT_ASSERT(0x115, cDyl_Initialized); diff --git a/src/d/d_s_play.cpp b/src/d/d_s_play.cpp index e91c61d02..b5c5c2db6 100644 --- a/src/d/d_s_play.cpp +++ b/src/d/d_s_play.cpp @@ -294,7 +294,7 @@ static int dScnPly_Draw(dScnPly_ply_c* i_this) { static s16 l_wipeType[] = {0, 0, 16, 17, 18, 1, 2, 1, 3, 3, 4, 4}; JUT_ASSERT(VERSION_SELECT(997, 1001, 1001), - dComIfGp_getNextStageWipe() < (sizeof(l_wipeType) / sizeof(l_wipeType[0]))); + dComIfGp_getNextStageWipe() < ARRAY_SIZE(l_wipeType)); if (strcmp(dComIfGp_getNextStageName(), "ENDING") == 0) { fopScnM_ChangeReq(i_this, PROC_ENDING_SCENE, 0, 5); @@ -1429,7 +1429,7 @@ s32 phase_5(dScnPly_ply_c* i_this) { const char** resName = PreLoadInfoT[preLoadNo].resName; s32 resNameNum = PreLoadInfoT[preLoadNo].resNameNum; if (resName != NULL && resName[0] != NULL) { - JUT_ASSERT(VERSION_SELECT(3804, 3824, 3824), resNameNum <= (sizeof(resPhase) / sizeof(resPhase[0]))); + JUT_ASSERT(VERSION_SELECT(3804, 3824, 3824), resNameNum <= ARRAY_SIZE(resPhase)); for (int i = 0; i < resNameNum; i++) { if (dComIfG_resLoad(&resPhase[i], resName[i]) != cPhs_COMPLEATE_e) { rt = cPhs_INIT_e; @@ -1452,7 +1452,7 @@ s32 phase_6(dScnPly_ply_c* i_this) { const s16* dylKeyTbl = PreLoadInfoT[preLoadNo].dylKeyTbl; s32 dylKeyTblNum = PreLoadInfoT[preLoadNo].dylKeyTblNum; if (dylKeyTbl != NULL && dylKeyTbl[0] != NULL) { - JUT_ASSERT(VERSION_SELECT(3838, 3858, 3858), dylKeyTblNum <= (sizeof(dylPhase) / sizeof(dylPhase[0]))); + JUT_ASSERT(VERSION_SELECT(3838, 3858, 3858), dylKeyTblNum <= ARRAY_SIZE(dylPhase)); for (int i = 0; i < dylKeyTblNum; i++) { if (cDylPhs::Link(&dylPhase[i], dylKeyTbl[i]) != cPhs_COMPLEATE_e) { rt = cPhs_INIT_e;