audio UB fix correction

This commit is contained in:
Sonic Dreamcaster
2026-01-04 08:10:28 -03:00
parent 1aa6dff53e
commit a6429d729b
+14 -4
View File
@@ -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) {