Fix NULL issues in OPL code
The 'ptr' pointer in the 'ptr += sizeof (FM_OPL)' expression could be nullptr. In such case, resulting value will be senseless and it should not be used.
This commit is contained in:
parent
9d69662001
commit
6a1c90b6d8
2 changed files with 15 additions and 7 deletions
|
@ -1958,23 +1958,23 @@ static void OPL_clock_changed(FM_OPL *OPL, uint32_t clock, uint32_t rate)
|
|||
/* 'rate' is sampling rate */
|
||||
static FM_OPL *OPLCreate(device_t *device, uint32_t clock, uint32_t rate, int type)
|
||||
{
|
||||
char *ptr;
|
||||
FM_OPL *OPL;
|
||||
int state_size;
|
||||
|
||||
if (FM_OPL::LockTable(device) == -1) return 0;
|
||||
|
||||
/* calculate OPL state size */
|
||||
state_size = sizeof(FM_OPL);
|
||||
int state_size = sizeof(FM_OPL);
|
||||
|
||||
#if BUILD_Y8950
|
||||
if (type&OPL_TYPE_ADPCM) state_size+= sizeof(YM_DELTAT);
|
||||
#endif
|
||||
|
||||
/* allocate memory block */
|
||||
ptr = (char *)auto_alloc_array_clear(device->machine(), uint8_t, state_size);
|
||||
char *ptr = (char *)auto_alloc_array_clear(device->machine(), uint8_t, state_size);
|
||||
if (!ptr) {
|
||||
device->logerror("Could not allocate memory during device creation");
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPL = (FM_OPL *)ptr;
|
||||
FM_OPL *OPL = (FM_OPL *)ptr;
|
||||
|
||||
ptr += sizeof(FM_OPL);
|
||||
|
||||
|
|
|
@ -2353,12 +2353,20 @@ static void OPL3ResetChip(OPL3 *chip)
|
|||
/* 'rate' is sampling rate */
|
||||
static OPL3 *OPL3Create(device_t *device, int clock, int rate, int type)
|
||||
{
|
||||
// Guard
|
||||
if (device == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
OPL3 *chip;
|
||||
|
||||
if (OPL3_LockTable(device) == -1) return 0;
|
||||
|
||||
/* allocate memory block */
|
||||
chip = auto_alloc_clear(device->machine(), OPL3 );
|
||||
if (chip == nullptr) {
|
||||
device->logerror("Could not allocate memory for OPL3 chip");
|
||||
return 0;
|
||||
}
|
||||
|
||||
chip->device = device;
|
||||
chip->type = type;
|
||||
|
|
Loading…
Add table
Reference in a new issue