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:
Johannes Schickel 2015-05-20 00:19:01 +02:00 committed by Matthew Hoops
parent 47aa40104d
commit 6f01600e12
2 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -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.
*