AUDIO: Fix abuse of driver IDs in OPL code.
If the driver id did not match the array index, the wrong driver entry would be accessed causing a crash in the worst case.
This commit is contained in:
parent
47aa40104d
commit
6f01600e12
2 changed files with 19 additions and 1 deletions
|
@ -63,6 +63,15 @@ Config::DriverId Config::parse(const Common::String &name) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
const Config::EmulatorDescription *Config::findDriver(DriverId id) {
|
||||
for (int i = 0; _drivers[i].name; ++i) {
|
||||
if (_drivers[i].id == id)
|
||||
return &_drivers[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Config::DriverId Config::detect(OplType type) {
|
||||
uint32 flags = 0;
|
||||
switch (type) {
|
||||
|
@ -90,8 +99,11 @@ Config::DriverId Config::detect(OplType type) {
|
|||
// When a valid driver is selected, check whether it supports
|
||||
// the requested OPL chip.
|
||||
if (drv != -1 && drv != kAuto) {
|
||||
const EmulatorDescription *driverDesc = findDriver(drv);
|
||||
// If the chip is supported, just use the driver.
|
||||
if ((flags & _drivers[drv].flags)) {
|
||||
if (!driverDesc) {
|
||||
warning("The selected OPL driver %d could not be found", drv);
|
||||
} else if ((flags & driverDesc->flags)) {
|
||||
return drv;
|
||||
} else {
|
||||
// Else we will output a warning and just
|
||||
|
|
|
@ -70,6 +70,12 @@ public:
|
|||
*/
|
||||
static DriverId parse(const Common::String &name);
|
||||
|
||||
/**
|
||||
* @return The driver description for the given id or 0 in case it is not
|
||||
* available.
|
||||
*/
|
||||
static const EmulatorDescription *findDriver(DriverId id);
|
||||
|
||||
/**
|
||||
* Detects a driver for the specific type.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue