Skip to content

Commit dc56188

Browse files
committed
bfsoundlib: Avoid uninitialized variables on invallid use
It was possible to make the library use uninitialized variables by putting the library into invalid state. While it was unlikely situation, better to not have uninitialized variables at all.
1 parent bf1946c commit dc56188

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

bfsoundlib/include/mssal.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,15 @@ struct VDI_CALL {
674674
int16_t AX;
675675
int16_t BX;
676676
int16_t CX;
677-
int16_t DX;
678-
int16_t SI;
677+
union {
678+
struct {
679+
int16_t DX;
680+
int16_t SI;
681+
};
682+
/** Some commands are transferring a pointer over DX:DI.
683+
* This definition makes it possible regardless of architecture. */
684+
uintptr_t pDXSI;
685+
};
679686
int16_t DI;
680687
};
681688

bfsoundlib/src/ailss.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ int32_t SS_configure_buffers(DIG_DRIVER *digdrv)
269269
pref[3] = DIG_F_MONO_16;
270270
break;
271271

272+
default:
272273
case DIG_F_STEREO_16:
273274
pref[0] = DIG_F_STEREO_16;
274275
pref[1] = DIG_F_STEREO_8;
@@ -366,6 +367,7 @@ int32_t SS_configure_buffers(DIG_DRIVER *digdrv)
366367
// Round half-buffer size to nearest binary power between 8 and
367368
// DIG_DMA_RESERVE / 2; ensure result within driver limits
368369
delta = LONG_MAX;
370+
match = bsmax;
369371

370372
for (n = 8; n <= (AIL_preference[DIG_DMA_RESERVE] / 2); n <<= 1)
371373
{

bfsoundlib/src/awe32use.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int AWEDefMemMap(MDI_DRIVER *mdidrv, short part_cnt, long *memMap, uint16_t memM
7272
regs.SI = 0;
7373
#else
7474
assert(sizeof(VDI_CALL) - offsetof(VDI_CALL, DX) >= sizeof(SF_DATA *));
75-
*(SF_DATA **)(&regs.DX) = awe_data;
75+
*(SF_DATA **)(&regs.pDXSI) = awe_data;
7676
#endif
7777
AIL_call_driver(mdidrv->drvr, MDI_VSE, &regs, &regs);
7878
return regs.AX;
@@ -102,7 +102,7 @@ SF_INFO *AWEGetSFInfo(MDI_DRIVER *mdidrv, short bank_no, uint8_t *hdr_data, uint
102102
regs.SI = 0;
103103
#else
104104
assert(sizeof(VDI_CALL) - offsetof(VDI_CALL, DX) >= sizeof(SF_DATA *));
105-
*(SF_DATA **)(&regs.DX) = awe_data;
105+
*(SF_DATA **)(&regs.pDXSI) = awe_data;
106106
#endif
107107
AIL_call_driver(mdidrv->drvr, MDI_VSE, &regs, &regs);
108108

@@ -111,7 +111,7 @@ SF_INFO *AWEGetSFInfo(MDI_DRIVER *mdidrv, short bank_no, uint8_t *hdr_data, uint
111111
#if defined(DOS)||defined(GO32)
112112
ret = MK_FP(CreateSelector(regs.DX), regs.SI);
113113
#else
114-
ret = *(SF_INFO **)(&regs.DX);
114+
ret = *(SF_INFO **)(&regs.pDXSI);
115115
#endif
116116
return ret;
117117
}
@@ -142,7 +142,7 @@ int AWEStreamSample(MDI_DRIVER *mdidrv, short bank_no, uint8_t *smpl_data, uint1
142142
regs.SI = 0;
143143
#else
144144
assert(sizeof(VDI_CALL) - offsetof(VDI_CALL, DX) >= sizeof(SF_DATA *));
145-
*(SF_DATA **)(&regs.DX) = awe_data;
145+
*(SF_DATA **)(&regs.pDXSI) = awe_data;
146146
#endif
147147

148148
AIL_call_driver(mdidrv->drvr, MDI_VSE, &regs, &regs);
@@ -173,7 +173,7 @@ int AWELoadPreset(MDI_DRIVER *mdidrv, short bank_no, uint8_t *preset_data, uint1
173173
regs.SI = 0;
174174
#else
175175
assert(sizeof(VDI_CALL) - offsetof(VDI_CALL, DX) >= sizeof(SF_DATA *));
176-
*(SF_DATA **)(&regs.DX) = awe_data;
176+
*(SF_DATA **)(&regs.pDXSI) = awe_data;
177177
#endif
178178
AIL_call_driver(mdidrv->drvr, MDI_VSE, &regs, &regs);
179179
return regs.AX;

bfsoundlib/src/cd.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ sbyte GetCDVolume(void)
217217
fvol = ogg_vorbis_stream_get_gain(&sound_music_stream);
218218
vol = fvol * (127.f / 1.f);
219219
break;
220+
default:
221+
vol = 0;
222+
SNDLOGFAIL("CDA play", "wrong CDType, cannot get volume");
223+
break;
220224
}
221225
return vol;
222226
}
@@ -237,6 +241,9 @@ void SetCDVolume(short vol)
237241
case CDTYP_OGG:
238242
ogg_vorbis_stream_set_gain(&sound_music_stream, vol * (1.f / 127.f));
239243
break;
244+
default:
245+
SNDLOGFAIL("CDA play", "wrong CDType, cannot set volume");
246+
break;
240247
}
241248
}
242249

0 commit comments

Comments
 (0)