Make driver loading signal failure, and fix case where setting a driver can cause a null pointer deref

This commit is contained in:
Jeffrey Pfau 2014-02-05 01:50:01 -08:00
parent 043d396320
commit a2a3f317b5
2 changed files with 8 additions and 4 deletions

View File

@ -83,9 +83,13 @@ void GBASIOSetDriver(struct GBASIO* sio, struct GBASIODriver* driver, enum GBASI
driver->p = sio; driver->p = sio;
if (driver->init) { 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; sio->activeDriver = driver;
if ((*driverLoc)->load) { if ((*driverLoc)->load) {
(*driverLoc)->load(*driverLoc); (*driverLoc)->load(*driverLoc);

View File

@ -21,11 +21,11 @@ struct GBASIO;
struct GBASIODriver { struct GBASIODriver {
struct GBASIO* p; struct GBASIO* p;
void (*init)(struct GBASIODriver* driver); int (*init)(struct GBASIODriver* driver);
void (*deinit)(struct GBASIODriver* driver); void (*deinit)(struct GBASIODriver* driver);
int (*load)(struct GBASIODriver* driver); int (*load)(struct GBASIODriver* driver);
int (*unload)(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); int32_t (*processEvents)(struct GBASIODriver* driver, int32_t cycles);
}; };