mirror of
https://github.com/zeldaret/mm.git
synced 2026-08-04 09:08:34 -04:00
A few UB fixes (#1272)
* Fix OoB in ObjDriftie * Fix OoB in EnHorseLinkChild * Fix negative shift in jpegdecode * more oob fixes * AVOID_UB * clean * huh? * change viint.h macros * objdriftice * ub labelling * review * review * fix z_parameter arrays * u32 cast * missing &
This commit is contained in:
@@ -1109,7 +1109,9 @@ void* AudioHeap_AllocPermanent(s32 tableType, s32 id, size_t size) {
|
||||
gAudioCtx.permanentEntries[index].size = size;
|
||||
//! @bug UB: missing return. "addr" is in v0 at this point, but doing an
|
||||
// explicit return uses an additional register.
|
||||
// return addr;
|
||||
#ifdef AVOID_UB
|
||||
return addr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void* AudioHeap_AllocSampleCache(size_t size, s32 sampleBankId, void* sampleAddr, s8 medium, s32 cache) {
|
||||
|
||||
@@ -738,6 +738,7 @@ void* AudioLoad_SyncLoad(s32 tableType, u32 id, s32* didAllocate) {
|
||||
romAddr = table->entries[realId].romAddr;
|
||||
switch (cachePolicy) {
|
||||
case CACHE_LOAD_PERMANENT:
|
||||
//! @bug UB: triggers an UB because this function is missing a return value.
|
||||
ramAddr = AudioHeap_AllocPermanent(tableType, realId, size);
|
||||
if (ramAddr == NULL) {
|
||||
return ramAddr;
|
||||
@@ -1108,6 +1109,7 @@ void* AudioLoad_AsyncLoadInner(s32 tableType, s32 id, s32 nChunks, s32 retData,
|
||||
|
||||
switch (cachePolicy) {
|
||||
case CACHE_LOAD_PERMANENT:
|
||||
//! @bug UB: triggers an UB because this function is missing a return value.
|
||||
ramAddr = AudioHeap_AllocPermanent(tableType, realId, size);
|
||||
if (ramAddr == NULL) {
|
||||
return ramAddr;
|
||||
|
||||
@@ -156,7 +156,7 @@ s32 JpegDecoder_ParseNextSymbol(JpegHuffmanTable* hTable, s16* outCoeff, s8* out
|
||||
if (sym) {
|
||||
*outCoeff = JpegDecoder_ReadBits(sym);
|
||||
if (*outCoeff < (1 << (sym - 1))) {
|
||||
*outCoeff += (-1 << sym) + 1;
|
||||
*outCoeff += (0xFFFFFFFF << sym) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+46
-19
@@ -159,16 +159,33 @@ static Gfx sScreenFillSetupDL[] = {
|
||||
|
||||
s16 D_801BF9B0 = 0;
|
||||
f32 D_801BF9B4[] = { 100.0f, 109.0f };
|
||||
s16 D_801BF9BC[] = { 0x226, 0x2A8, 0x2A8, 0x2A8 };
|
||||
s16 D_801BF9BC[] = {
|
||||
0x226, // EQUIP_SLOT_B
|
||||
0x2A8, // EQUIP_SLOT_C_LEFT
|
||||
0x2A8, // EQUIP_SLOT_C_DOWN
|
||||
0x2A8, // EQUIP_SLOT_C_RIGHT
|
||||
};
|
||||
s16 D_801BF9C4[] = { 0x9E, 0x9B };
|
||||
s16 D_801BF9C8[] = { 0x17, 0x16 };
|
||||
f32 D_801BF9CC[] = { -380.0f, -350.0f };
|
||||
s16 D_801BF9D4[] = { 0xA7, 0xE3 };
|
||||
s16 D_801BF9D8[] = { 0xF9, 0x10F };
|
||||
s16 D_801BF9DC[] = { 0x11, 0x12 };
|
||||
s16 D_801BF9E0[] = { 0x22, 0x12 };
|
||||
s16 D_801BF9E4[] = { 0x23F, 0x26C };
|
||||
s16 D_801BF9E8[] = { 0x26C, 0x26C };
|
||||
s16 D_801BF9D4[] = {
|
||||
0xA7, // EQUIP_SLOT_B
|
||||
0xE3, // EQUIP_SLOT_C_LEFT
|
||||
0xF9, // EQUIP_SLOT_C_DOWN
|
||||
0x10F, // EQUIP_SLOT_C_RIGHT
|
||||
};
|
||||
s16 D_801BF9DC[] = {
|
||||
0x11, // EQUIP_SLOT_B
|
||||
0x12, // EQUIP_SLOT_C_LEFT
|
||||
0x22, // EQUIP_SLOT_C_DOWN
|
||||
0x12, // EQUIP_SLOT_C_RIGHT
|
||||
};
|
||||
s16 D_801BF9E4[] = {
|
||||
0x23F, // EQUIP_SLOT_B
|
||||
0x26C, // EQUIP_SLOT_C_LEFT
|
||||
0x26C, // EQUIP_SLOT_C_DOWN
|
||||
0x26C, // EQUIP_SLOT_C_RIGHT
|
||||
};
|
||||
|
||||
s16 sFinalHoursClockDigitsRed = 0;
|
||||
s16 sFinalHoursClockFrameEnvRed = 0;
|
||||
@@ -3848,8 +3865,12 @@ void Interface_DrawItemButtons(PlayState* play) {
|
||||
// Remnant of OoT
|
||||
130, 136, 136, 136, 136,
|
||||
};
|
||||
static s16 D_801BFAF4[] = { 0x1D, 0x1B };
|
||||
static s16 D_801BFAF8[] = { 0x1B, 0x1B };
|
||||
static s16 D_801BFAF4[] = {
|
||||
0x1D, // EQUIP_SLOT_B
|
||||
0x1B, // EQUIP_SLOT_C_LEFT
|
||||
0x1B, // EQUIP_SLOT_C_DOWN
|
||||
0x1B, // EQUIP_SLOT_C_RIGHT
|
||||
};
|
||||
InterfaceContext* interfaceCtx = &play->interfaceCtx;
|
||||
Player* player = GET_PLAYER(play);
|
||||
PauseContext* pauseCtx = &play->pauseCtx;
|
||||
@@ -3863,21 +3884,27 @@ void Interface_DrawItemButtons(PlayState* play) {
|
||||
gDPSetCombineMode(OVERLAY_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
|
||||
|
||||
// B Button Color & Texture
|
||||
OVERLAY_DISP = Gfx_DrawTexRectIA8_DropShadow(OVERLAY_DISP, gButtonBackgroundTex, 0x20, 0x20, D_801BF9D4[0],
|
||||
D_801BF9DC[0], D_801BFAF4[0], D_801BFAF4[0], D_801BF9E4[0] * 2,
|
||||
D_801BF9E4[0] * 2, 100, 255, 120, interfaceCtx->bAlpha);
|
||||
OVERLAY_DISP = Gfx_DrawTexRectIA8_DropShadow(
|
||||
OVERLAY_DISP, gButtonBackgroundTex, 0x20, 0x20, D_801BF9D4[EQUIP_SLOT_B], D_801BF9DC[EQUIP_SLOT_B],
|
||||
D_801BFAF4[EQUIP_SLOT_B], D_801BFAF4[EQUIP_SLOT_B], D_801BF9E4[EQUIP_SLOT_B] * 2, D_801BF9E4[EQUIP_SLOT_B] * 2,
|
||||
100, 255, 120, interfaceCtx->bAlpha);
|
||||
gDPPipeSync(OVERLAY_DISP++);
|
||||
|
||||
// C-Left Button Color & Texture
|
||||
OVERLAY_DISP = Gfx_DrawRect_DropShadow(OVERLAY_DISP, D_801BF9D4[1], D_801BF9DC[1], D_801BFAF4[1], D_801BFAF4[1],
|
||||
D_801BF9E4[1] * 2, D_801BF9E4[1] * 2, 255, 240, 0, interfaceCtx->cLeftAlpha);
|
||||
OVERLAY_DISP = Gfx_DrawRect_DropShadow(OVERLAY_DISP, D_801BF9D4[EQUIP_SLOT_C_LEFT], D_801BF9DC[EQUIP_SLOT_C_LEFT],
|
||||
D_801BFAF4[EQUIP_SLOT_C_LEFT], D_801BFAF4[EQUIP_SLOT_C_LEFT],
|
||||
D_801BF9E4[EQUIP_SLOT_C_LEFT] * 2, D_801BF9E4[EQUIP_SLOT_C_LEFT] * 2, 255,
|
||||
240, 0, interfaceCtx->cLeftAlpha);
|
||||
// C-Down Button Color & Texture
|
||||
OVERLAY_DISP = Gfx_DrawRect_DropShadow(OVERLAY_DISP, D_801BF9D8[0], D_801BF9E0[0], D_801BFAF8[0], D_801BFAF8[0],
|
||||
D_801BF9E4[2] * 2, D_801BF9E4[2] * 2, 255, 240, 0, interfaceCtx->cDownAlpha);
|
||||
OVERLAY_DISP = Gfx_DrawRect_DropShadow(OVERLAY_DISP, D_801BF9D4[EQUIP_SLOT_C_DOWN], D_801BF9DC[EQUIP_SLOT_C_DOWN],
|
||||
D_801BFAF4[EQUIP_SLOT_C_DOWN], D_801BFAF4[EQUIP_SLOT_C_DOWN],
|
||||
D_801BF9E4[EQUIP_SLOT_C_DOWN] * 2, D_801BF9E4[EQUIP_SLOT_C_DOWN] * 2, 255,
|
||||
240, 0, interfaceCtx->cDownAlpha);
|
||||
// C-Right Button Color & Texture
|
||||
OVERLAY_DISP =
|
||||
Gfx_DrawRect_DropShadow(OVERLAY_DISP, D_801BF9D8[1], D_801BF9E0[1], D_801BFAF8[1], D_801BFAF8[1],
|
||||
D_801BF9E4[3] * 2, D_801BF9E4[3] * 2, 255, 240, 0, interfaceCtx->cRightAlpha);
|
||||
OVERLAY_DISP = Gfx_DrawRect_DropShadow(OVERLAY_DISP, D_801BF9D4[EQUIP_SLOT_C_RIGHT], D_801BF9DC[EQUIP_SLOT_C_RIGHT],
|
||||
D_801BFAF4[EQUIP_SLOT_C_RIGHT], D_801BFAF4[EQUIP_SLOT_C_RIGHT],
|
||||
D_801BF9E4[EQUIP_SLOT_C_RIGHT] * 2, D_801BF9E4[EQUIP_SLOT_C_RIGHT] * 2, 255,
|
||||
240, 0, interfaceCtx->cRightAlpha);
|
||||
|
||||
if (!IS_PAUSE_STATE_GAMEOVER) {
|
||||
if ((play->pauseCtx.state != PAUSE_STATE_OFF) || (play->pauseCtx.debugEditor != DEBUG_EDITOR_NONE)) {
|
||||
|
||||
+4
-4
@@ -153,14 +153,14 @@ void ViMode_Configure(OSViMode* viMode, s32 type, s32 tvType, s32 loRes, s32 ant
|
||||
viMode->comRegs.vSync++;
|
||||
if (tvType == OS_TV_MPAL) {
|
||||
viMode->comRegs.hSync += HSYNC(1, 4);
|
||||
viMode->comRegs.leap += LEAP((u16)-4, (u16)-2);
|
||||
viMode->comRegs.leap += LEAP(-4, -2);
|
||||
}
|
||||
} else {
|
||||
viMode->fldRegs[0].vStart += START((u16)-3, (u16)-2);
|
||||
viMode->fldRegs[0].vStart += START(-3, -2);
|
||||
if (tvType == OS_TV_MPAL) {
|
||||
viMode->fldRegs[0].vBurst += BURST((u8)-2, (u8)-1, 12, -1);
|
||||
viMode->fldRegs[0].vBurst += BURST(-2, -1, 12, -1);
|
||||
} else if (tvType == OS_TV_PAL) {
|
||||
viMode->fldRegs[1].vBurst += BURST((u8)-2, (u8)-1, 2, 0);
|
||||
viMode->fldRegs[1].vBurst += BURST(-2, -1, 2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,10 +39,10 @@ ActorInit En_Horse_Link_Child_InitVars = {
|
||||
(ActorFunc)EnHorseLinkChild_Draw,
|
||||
};
|
||||
|
||||
AnimationHeader* D_808DFEC0[] = { &object_horse_link_child_Anim_006D44, &object_horse_link_child_Anim_007468 };
|
||||
|
||||
AnimationHeader* D_808DFEC8[] = { &object_horse_link_child_Anim_007D50, &object_horse_link_child_Anim_0043AC,
|
||||
&object_horse_link_child_Anim_002F98 };
|
||||
AnimationHeader* D_808DFEC0[] = {
|
||||
&object_horse_link_child_Anim_006D44, &object_horse_link_child_Anim_007468, &object_horse_link_child_Anim_007D50,
|
||||
&object_horse_link_child_Anim_0043AC, &object_horse_link_child_Anim_002F98,
|
||||
};
|
||||
|
||||
static ColliderJntSphElementInit sJntSphElementsInit[] = {
|
||||
{
|
||||
@@ -444,7 +444,7 @@ void func_808DF620(EnHorseLinkChild* this, PlayState* play) {
|
||||
if (Math_CosS(sp36) < 0.0f) {
|
||||
this->unk_148 = 2;
|
||||
Animation_Change(&this->skin.skelAnime, D_808DFEC0[this->unk_148], D_808DFF18[this->unk_148], 0.0f,
|
||||
Animation_GetLastFrame(D_808DFEC8[0]), ANIMMODE_ONCE, -5.0f);
|
||||
Animation_GetLastFrame(D_808DFEC0[2]), ANIMMODE_ONCE, -5.0f);
|
||||
} else {
|
||||
func_808DF560(this);
|
||||
}
|
||||
|
||||
@@ -163,19 +163,19 @@ void func_80A66930(ObjDrifticeStruct2* arg0, ObjDriftice* this, s16* arg2, s16*
|
||||
temp_f20 = 0.01f;
|
||||
}
|
||||
|
||||
Math_StepToS(&arg0->unk_00[1], 1200.0f * temp_f20, 0x64);
|
||||
Math_StepToS(&arg0->unk_02, 1200.0f * temp_f20, 0x64);
|
||||
phi_s0 = 2500.0f * temp_f20;
|
||||
Math_StepToS(&arg0->unk_00[3], Math_CosS(arg0->unk_00[2] * 6.5536f) * (120.0f * temp_f20), 0x28);
|
||||
Math_StepToS(&arg0->unk_06, Math_CosS(arg0->unk_04 * 6.5536f) * (120.0f * temp_f20), 0x28);
|
||||
Math_StepToF(&arg0->unk_08, 1.0f, 0.02f);
|
||||
} else {
|
||||
Math_StepToS(&arg0->unk_00[1], 0, 0x96);
|
||||
Math_StepToS(&arg0->unk_02, 0, 0x96);
|
||||
phi_s0 = 0;
|
||||
Math_StepToS(&arg0->unk_00[3], 20, 7);
|
||||
Math_StepToS(&arg0->unk_06, 20, 7);
|
||||
Math_StepToF(&arg0->unk_08, 0.0f, 0.02f);
|
||||
}
|
||||
Math_ScaledStepToS(arg0->unk_00, this->dyna.actor.yawTowardsPlayer, arg0->unk_00[1]);
|
||||
*arg3 = arg0->unk_00[0];
|
||||
Math_ScaledStepToS(&arg0->unk_00[2], phi_s0, arg0->unk_00[3]);
|
||||
Math_ScaledStepToS(&arg0->unk_00, this->dyna.actor.yawTowardsPlayer, arg0->unk_02);
|
||||
*arg3 = arg0->unk_00;
|
||||
Math_ScaledStepToS(&arg0->unk_04, phi_s0, arg0->unk_06);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
temp_s0 = &arg0->unk_0C[i];
|
||||
@@ -195,8 +195,7 @@ void func_80A66930(ObjDrifticeStruct2* arg0, ObjDriftice* this, s16* arg2, s16*
|
||||
|
||||
temp_f22 *= arg0->unk_08;
|
||||
|
||||
//! FAKE:
|
||||
*arg2 = arg0->unk_00[2] + (s32)((void)0, temp_f22);
|
||||
*arg2 = (s32)temp_f22 + arg0->unk_04;
|
||||
}
|
||||
|
||||
void func_80A66C4C(ObjDrifticeStruct4* arg0, ObjDriftice* this, s16* arg2, s16* arg3) {
|
||||
|
||||
@@ -23,8 +23,10 @@ typedef struct {
|
||||
} ObjDrifticeStruct3; // size = 0x14
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ s16 unk_00[2];
|
||||
/* 0x04 */ f32 unk_04;
|
||||
/* 0x00 */ s16 unk_00;
|
||||
/* 0x02 */ s16 unk_02;
|
||||
/* 0x04 */ s16 unk_04;
|
||||
/* 0x06 */ s16 unk_06;
|
||||
/* 0x08 */ f32 unk_08;
|
||||
/* 0x0C */ ObjDrifticeStruct3 unk_0C[2];
|
||||
} ObjDrifticeStruct2; // size = 0x34
|
||||
|
||||
Reference in New Issue
Block a user