all repos — mgba @ a2a3f317b5d393d5f14865b5233aef9adf864787

mGBA Game Boy Advance Emulator

Make driver loading signal failure, and fix case where setting a driver can cause a null pointer deref
Jeffrey Pfau jeffrey@endrift.com
Wed, 05 Feb 2014 01:50:01 -0800
commit

a2a3f317b5d393d5f14865b5233aef9adf864787

parent

043d396320cf21acdaf507de80673c1e8528d3f3

2 files changed, 8 insertions(+), 4 deletions(-)

jump to
M src/gba/gba-sio.csrc/gba/gba-sio.c

@@ -83,9 +83,13 @@ if (driver) {

driver->p = sio; if (driver->init) { - driver->init(driver); + if (!driver->init(driver)) { + driver->deinit(driver); + GBALog(sio->p, GBA_LOG_ERROR, "Could not initialize SIO driver"); + return; + } } - if (*driverLoc == sio->activeDriver) { + if (*driverLoc && *driverLoc == sio->activeDriver) { sio->activeDriver = driver; if ((*driverLoc)->load) { (*driverLoc)->load(*driverLoc);
M src/gba/gba-sio.hsrc/gba/gba-sio.h

@@ -21,11 +21,11 @@

struct GBASIODriver { struct GBASIO* p; - void (*init)(struct GBASIODriver* driver); + int (*init)(struct GBASIODriver* driver); void (*deinit)(struct GBASIODriver* driver); int (*load)(struct GBASIODriver* driver); int (*unload)(struct GBASIODriver* driver); - void (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); + int (*writeRegister)(struct GBASIODriver* driver, uint32_t address, uint16_t value); int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles); };