From 361fa594b30005edaa8aef5f6b02ac8b15149cba Mon Sep 17 00:00:00 2001 From: ExpoSeed <> Date: Sat, 15 May 2021 15:56:17 -0500 Subject: Various BUGFIXes and UBFIXes --- src/siirtc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/siirtc.c') diff --git a/src/siirtc.c b/src/siirtc.c index 5c153a841..01d2e0e72 100644 --- a/src/siirtc.c +++ b/src/siirtc.c @@ -417,6 +417,9 @@ static u8 ReadData() u8 i; u8 temp; u8 value; + #ifdef UBFIX + value = 0; + #endif for (i = 0; i < 8; i++) { @@ -428,7 +431,7 @@ static u8 ReadData() GPIO_PORT_DATA = SCK_HI | CS_HI; temp = ((GPIO_PORT_DATA & SIO_HI) >> 1); - value = (value >> 1) | (temp << 7); // UB: accessing uninitialized var + value = (value >> 1) | (temp << 7); // UB: value is uninitialized on first iteration } return value; -- cgit v1.2.3 From ff16812f99f62a495975e7cc3c68ede339171765 Mon Sep 17 00:00:00 2001 From: gAlfonso-bit <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sun, 23 May 2021 10:56:37 -0400 Subject: UBFix: uninitialized variables in m4a engine and siirtc.c (#1432) --- src/siirtc.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/siirtc.c') diff --git a/src/siirtc.c b/src/siirtc.c index 01d2e0e72..5f4fc0a23 100644 --- a/src/siirtc.c +++ b/src/siirtc.c @@ -71,6 +71,7 @@ static bool8 sLocked; static int WriteCommand(u8 value); static int WriteData(u8 value); static u8 ReadData(); + static void EnableGpioPortRead(); static void DisableGpioPortRead(); @@ -98,8 +99,12 @@ u8 SiiRtcProbe(void) errorCode = 0; +#ifdef BUGFIX + if (!(rtc.status & SIIRTCINFO_24HOUR) || (rtc.status & SIIRTCINFO_POWER)) +#else if ((rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == SIIRTCINFO_POWER || (rtc.status & (SIIRTCINFO_POWER | SIIRTCINFO_24HOUR)) == 0) +#endif { // 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) { - u8 result; + bool8 result; struct SiiRtcInfo rtc; if (sLocked == TRUE) @@ -392,7 +397,11 @@ static int WriteCommand(u8 value) 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) @@ -409,7 +418,11 @@ static int WriteData(u8 value) 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() @@ -417,9 +430,10 @@ static u8 ReadData() u8 i; u8 temp; u8 value; - #ifdef UBFIX + +#ifdef UBFIX value = 0; - #endif +#endif for (i = 0; i < 8; i++) { @@ -431,7 +445,7 @@ static u8 ReadData() GPIO_PORT_DATA = SCK_HI | CS_HI; 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; @@ -439,10 +453,10 @@ static u8 ReadData() static void EnableGpioPortRead() { - GPIO_PORT_READ_ENABLE = 1; + GPIO_PORT_READ_ENABLE = TRUE; } static void DisableGpioPortRead() { - GPIO_PORT_READ_ENABLE = 0; + GPIO_PORT_READ_ENABLE = FALSE; } -- cgit v1.2.3