mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2025-01-27 05:43:51 +01:00
UBFix: uninitialized variables in m4a engine and siirtc.c (#1432)
This commit is contained in:
parent
ffbbc88801
commit
ff16812f99
@ -1525,6 +1525,10 @@ void ply_xwave(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track
|
|||||||
{
|
{
|
||||||
u32 wav;
|
u32 wav;
|
||||||
|
|
||||||
|
#ifdef UBFIX
|
||||||
|
wav = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
READ_XCMD_BYTE(wav, 0) // UB: uninitialized variable
|
READ_XCMD_BYTE(wav, 0) // UB: uninitialized variable
|
||||||
READ_XCMD_BYTE(wav, 1)
|
READ_XCMD_BYTE(wav, 1)
|
||||||
READ_XCMD_BYTE(wav, 2)
|
READ_XCMD_BYTE(wav, 2)
|
||||||
@ -1592,6 +1596,10 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra
|
|||||||
{
|
{
|
||||||
u32 unk;
|
u32 unk;
|
||||||
|
|
||||||
|
#ifdef UBFIX
|
||||||
|
unk = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable
|
READ_XCMD_BYTE(unk, 0) // UB: uninitialized variable
|
||||||
READ_XCMD_BYTE(unk, 1)
|
READ_XCMD_BYTE(unk, 1)
|
||||||
|
|
||||||
@ -1611,6 +1619,7 @@ void ply_xcmd_0C(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tra
|
|||||||
void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
|
void ply_xcmd_0D(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track)
|
||||||
{
|
{
|
||||||
u32 unk;
|
u32 unk;
|
||||||
|
|
||||||
#ifdef UBFIX
|
#ifdef UBFIX
|
||||||
unk = 0;
|
unk = 0;
|
||||||
#endif
|
#endif
|
||||||
|
30
src/siirtc.c
30
src/siirtc.c
@ -71,6 +71,7 @@ static bool8 sLocked;
|
|||||||
static int WriteCommand(u8 value);
|
static int WriteCommand(u8 value);
|
||||||
static int WriteData(u8 value);
|
static int WriteData(u8 value);
|
||||||
static u8 ReadData();
|
static u8 ReadData();
|
||||||
|
|
||||||
static void EnableGpioPortRead();
|
static void EnableGpioPortRead();
|
||||||
static void DisableGpioPortRead();
|
static void DisableGpioPortRead();
|
||||||
|
|
||||||
@ -98,8 +99,12 @@ u8 SiiRtcProbe(void)
|
|||||||
|
|
||||||
errorCode = 0;
|
errorCode = 0;
|
||||||
|
|
||||||
|
#ifdef BUGFIX
|
||||||
|
if (!(rtc.status & SIIRTCINFO_24HOUR) || (rtc.status & SIIRTCINFO_POWER))
|
||||||
|
#else
|
||||||
if ((rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == SIIRTCINFO_POWER
|
if ((rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == SIIRTCINFO_POWER
|
||||||
|| (rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == 0)
|
|| (rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == 0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
// The RTC is in 12-hour mode. Reset it and switch to 24-hour mode.
|
// The RTC is in 12-hour mode. Reset it and switch to 24-hour mode.
|
||||||
|
|
||||||
@ -131,7 +136,7 @@ u8 SiiRtcProbe(void)
|
|||||||
|
|
||||||
bool8 SiiRtcReset(void)
|
bool8 SiiRtcReset(void)
|
||||||
{
|
{
|
||||||
u8 result;
|
bool8 result;
|
||||||
struct SiiRtcInfo rtc;
|
struct SiiRtcInfo rtc;
|
||||||
|
|
||||||
if (sLocked == TRUE)
|
if (sLocked == TRUE)
|
||||||
@ -392,7 +397,11 @@ static int WriteCommand(u8 value)
|
|||||||
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
|
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
|
||||||
}
|
}
|
||||||
|
|
||||||
// control reaches end of non-void function
|
// Nothing uses the returned value from this function,
|
||||||
|
// so the undefined behavior is harmless in the vanilla game.
|
||||||
|
#ifdef UBFIX
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int WriteData(u8 value)
|
static int WriteData(u8 value)
|
||||||
@ -409,7 +418,11 @@ static int WriteData(u8 value)
|
|||||||
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
|
GPIO_PORT_DATA = (temp << 1) | SCK_HI | CS_HI;
|
||||||
}
|
}
|
||||||
|
|
||||||
// control reaches end of non-void function
|
// Nothing uses the returned value from this function,
|
||||||
|
// so the undefined behavior is harmless in the vanilla game.
|
||||||
|
#ifdef UBFIX
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static u8 ReadData()
|
static u8 ReadData()
|
||||||
@ -417,9 +430,10 @@ static u8 ReadData()
|
|||||||
u8 i;
|
u8 i;
|
||||||
u8 temp;
|
u8 temp;
|
||||||
u8 value;
|
u8 value;
|
||||||
#ifdef UBFIX
|
|
||||||
|
#ifdef UBFIX
|
||||||
value = 0;
|
value = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
@ -431,7 +445,7 @@ static u8 ReadData()
|
|||||||
GPIO_PORT_DATA = SCK_HI | CS_HI;
|
GPIO_PORT_DATA = SCK_HI | CS_HI;
|
||||||
|
|
||||||
temp = ((GPIO_PORT_DATA & SIO_HI) >> 1);
|
temp = ((GPIO_PORT_DATA & SIO_HI) >> 1);
|
||||||
value = (value >> 1) | (temp << 7); // UB: value is uninitialized on first iteration
|
value = (value >> 1) | (temp << 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -439,10 +453,10 @@ static u8 ReadData()
|
|||||||
|
|
||||||
static void EnableGpioPortRead()
|
static void EnableGpioPortRead()
|
||||||
{
|
{
|
||||||
GPIO_PORT_READ_ENABLE = 1;
|
GPIO_PORT_READ_ENABLE = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DisableGpioPortRead()
|
static void DisableGpioPortRead()
|
||||||
{
|
{
|
||||||
GPIO_PORT_READ_ENABLE = 0;
|
GPIO_PORT_READ_ENABLE = FALSE;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user