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
2 files changed,
8 insertions(+),
4 deletions(-)
M
src/gba/gba-sio.c
→
src/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.h
→
src/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); };