summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSonic Dreamcaster <alejandro.asenjo88@gmail.com>2026-01-04 08:10:28 -0300
committerSonic Dreamcaster <alejandro.asenjo88@gmail.com>2026-01-04 08:10:28 -0300
commita6429d729b4ffb7939ac73fd9c8f6c46e4760131 (patch)
treeffe52f3e54413da5af433924ddb772c3e5895ef3
parent1aa6dff53ee6e068ec8eb3b313bb0ff7980482b3 (diff)
audio UB fix correction
-rw-r--r--src/audio/audio_heap.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/audio/audio_heap.c b/src/audio/audio_heap.c
index b1e0cb49..d8207e8a 100644
--- a/src/audio/audio_heap.c
+++ b/src/audio/audio_heap.c
@@ -994,15 +994,25 @@ void AudioHeap_DiscardSampleCaches(void) {
for (fontId = 0; fontId < numFonts; fontId++) {
sampleBankId1 = gSoundFontList[fontId].sampleBankId1;
sampleBankId2 = gSoundFontList[fontId].sampleBankId2;
- // @port: avoid reading from garbage memory,
+#ifdef AVOID_UB
// F-Zero X newer version of this audio driver has this fix:
- if (((sampleBankId1 != SAMPLES_NONE_U) /* && (entry->sampleBankId == sampleBankId1) */) ||
- ((sampleBankId2 != SAMPLES_NONE) /* && (entry->sampleBankId == sampleBankId2)*/ ) /* ||
- (entry->sampleBankId == SAMPLES_SFX) */) {
+ if ((sampleBankId1 != SAMPLES_NONE_U) || (sampleBankId2 != SAMPLES_NONE)) {
+#else
+ //! @bug: entry is uninitialized, reading from garbage memory.
+ if (((sampleBankId1 != SAMPLES_NONE_U) && (entry->sampleBankId == sampleBankId1)) ||
+ ((sampleBankId2 != SAMPLES_NONE) && (entry->sampleBankId == sampleBankId2)) ||
+ (entry->sampleBankId == SAMPLES_SFX)) {
+#endif
if (((void*) AudioHeap_SearchCaches(FONT_TABLE, CACHE_PERMANENT, fontId) != NULL) &&
((gFontLoadStatus[fontId] > 1) != 0)) {
for (i = 0; i < gPersistentSampleCache.numEntries; i++) {
entry = &gPersistentSampleCache.entries[i];
+#ifdef AVOID_UB
+ if ((sampleBankId1 != entry->sampleBankId) && (sampleBankId2 != entry->sampleBankId) &&
+ (entry->sampleBankId != SAMPLES_SFX)) {
+ break;
+ }
+#endif
for (instId = 0; instId < gSoundFontList[fontId].numInstruments; instId++) {
instrument = Audio_GetInstrument(fontId, instId);
if (instrument != NULL) {