aboutsummaryrefslogtreecommitdiff
path: root/audio/fmopl.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2015-05-20 00:19:01 +0200
committerMatthew Hoops2015-07-07 20:19:41 -0400
commit6f01600e12ba14acde8a6557716783861dc014d1 (patch)
tree2a32a7d5e9e7abc7236d1898e6606aa7c34bdff8 /audio/fmopl.cpp
parent47aa40104d11d92ea3c53390851e719d133fc7b9 (diff)
downloadscummvm-rg350-6f01600e12ba14acde8a6557716783861dc014d1.tar.gz
scummvm-rg350-6f01600e12ba14acde8a6557716783861dc014d1.tar.bz2
scummvm-rg350-6f01600e12ba14acde8a6557716783861dc014d1.zip
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.
Diffstat (limited to 'audio/fmopl.cpp')
-rw-r--r--audio/fmopl.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/audio/fmopl.cpp b/audio/fmopl.cpp
index 30229ea6bf..00e49ef598 100644
--- a/audio/fmopl.cpp
+++ b/audio/fmopl.cpp
@@ -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