mirror of
https://github.com/rkujawa/rk65c02.git
synced 2024-12-12 10:30:23 +00:00
Simplify error handling if malloc fails.
There's no way to reliable handle out of memory situation in an emulator. So just bail out by raising assertion.
This commit is contained in:
parent
0896956337
commit
2cc9d86c64
@ -75,11 +75,9 @@ assemble_single_buf(uint8_t **buf, uint8_t *bsize, char *mnemonic, addressing_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
*bsize = id.size;
|
*bsize = id.size;
|
||||||
|
|
||||||
*buf = GC_MALLOC(id.size);
|
*buf = GC_MALLOC(id.size);
|
||||||
if(*buf == NULL) {
|
assert(*buf != NULL);
|
||||||
rk65c02_log(LOG_ERROR, "Error allocating assembly buffer.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fill the buffer */
|
/* fill the buffer */
|
||||||
memset(*buf, 0, id.size);
|
memset(*buf, 0, id.size);
|
||||||
|
@ -35,6 +35,7 @@ bus_device_add(bus_t *b, device_t *d, uint16_t addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dm = (device_mapping_t *) GC_MALLOC(sizeof(device_mapping_t));
|
dm = (device_mapping_t *) GC_MALLOC(sizeof(device_mapping_t));
|
||||||
|
assert(dm != NULL);
|
||||||
|
|
||||||
dm->dev = d;
|
dm->dev = d;
|
||||||
dm->addr = addr;
|
dm->addr = addr;
|
||||||
|
@ -46,10 +46,7 @@ debug_trace_savestate(rk65c02emu_t *e, uint16_t address, instrdef_t *id,
|
|||||||
trace_t *tr;
|
trace_t *tr;
|
||||||
|
|
||||||
tr = (trace_t *) GC_MALLOC(sizeof(trace_t));
|
tr = (trace_t *) GC_MALLOC(sizeof(trace_t));
|
||||||
if (tr == NULL) {
|
assert(tr != NULL);
|
||||||
fprintf(stderr, "Error allocating trace structure.\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr->address = address;
|
tr->address = address;
|
||||||
|
|
||||||
|
@ -68,9 +68,11 @@ device_fb_init()
|
|||||||
d->write_1 = device_fb_write_1;
|
d->write_1 = device_fb_write_1;
|
||||||
|
|
||||||
f = GC_MALLOC(sizeof(struct fb_state));
|
f = GC_MALLOC(sizeof(struct fb_state));
|
||||||
|
assert(f != NULL);
|
||||||
d->aux = f;
|
d->aux = f;
|
||||||
|
|
||||||
f->cram = GC_MALLOC(FB_AS_SIZE);
|
f->cram = GC_MALLOC(FB_AS_SIZE);
|
||||||
|
assert(f->cram != NULL);
|
||||||
memset(d->aux, 0, FB_AS_SIZE);
|
memset(d->aux, 0, FB_AS_SIZE);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
@ -41,7 +41,6 @@ device_ram_init(uint16_t size)
|
|||||||
device_t *d;
|
device_t *d;
|
||||||
|
|
||||||
d = (device_t *) GC_MALLOC(sizeof(device_t));
|
d = (device_t *) GC_MALLOC(sizeof(device_t));
|
||||||
|
|
||||||
assert(d != NULL);
|
assert(d != NULL);
|
||||||
|
|
||||||
d->name = "RAM";
|
d->name = "RAM";
|
||||||
@ -52,6 +51,8 @@ device_ram_init(uint16_t size)
|
|||||||
d->finish = NULL;
|
d->finish = NULL;
|
||||||
|
|
||||||
d->aux = GC_MALLOC(size);
|
d->aux = GC_MALLOC(size);
|
||||||
|
assert(d->aux != NULL);
|
||||||
|
|
||||||
memset(d->aux, 0, size);
|
memset(d->aux, 0, size);
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
|
@ -89,6 +89,7 @@ device_serial_init()
|
|||||||
d->finish = device_serial_finish;
|
d->finish = device_serial_finish;
|
||||||
|
|
||||||
dp = (struct device_serial_priv *) GC_MALLOC(sizeof(struct device_serial_priv));
|
dp = (struct device_serial_priv *) GC_MALLOC(sizeof(struct device_serial_priv));
|
||||||
|
assert(dp != NULL);
|
||||||
d->aux = dp;
|
d->aux = dp;
|
||||||
|
|
||||||
if (mkfifo(txpipepath, S_IRUSR | S_IWUSR) != 0) {
|
if (mkfifo(txpipepath, S_IRUSR | S_IWUSR) != 0) {
|
||||||
|
@ -73,11 +73,7 @@ instruction_string_get(instruction_t *i)
|
|||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
str = GC_MALLOC(INSTR_STR_LEN);
|
str = GC_MALLOC(INSTR_STR_LEN);
|
||||||
if (str == NULL) {
|
assert(str != NULL);
|
||||||
rk65c02_log(LOG_CRIT, "Error allocating memory for buffer: %s.",
|
|
||||||
strerror(errno));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memset(str, 0, INSTR_STR_LEN);
|
memset(str, 0, INSTR_STR_LEN);
|
||||||
|
|
||||||
id = instruction_decode(i->opcode);
|
id = instruction_decode(i->opcode);
|
||||||
|
@ -25,6 +25,7 @@ rk65c02_load_rom(const char *path, uint16_t load_addr, bus_t *b)
|
|||||||
|
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
b = GC_MALLOC(sizeof(bus_t));
|
b = GC_MALLOC(sizeof(bus_t));
|
||||||
|
assert(b != NULL);
|
||||||
*b = bus_init_with_default_devs();
|
*b = bus_init_with_default_devs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,11 +216,7 @@ rk65c02_regs_string_get(reg_state_t regs)
|
|||||||
|
|
||||||
/* XXX: string allocation to a separate utility function? */
|
/* XXX: string allocation to a separate utility function? */
|
||||||
str = GC_MALLOC(REGS_STR_LEN);
|
str = GC_MALLOC(REGS_STR_LEN);
|
||||||
if (str == NULL) {
|
assert(str != NULL);
|
||||||
rk65c02_log(LOG_CRIT, "Error allocating memory for buffer: %s.",
|
|
||||||
strerror(errno));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
memset(str, 0, REGS_STR_LEN);
|
memset(str, 0, REGS_STR_LEN);
|
||||||
|
|
||||||
snprintf(str, REGS_STR_LEN, "A: %X X: %X Y: %X PC: %X SP: %X P: %c%c%c%c%c%c%c%c",
|
snprintf(str, REGS_STR_LEN, "A: %X X: %X Y: %X PC: %X SP: %X P: %c%c%c%c%c%c%c%c",
|
||||||
|
Loading…
Reference in New Issue
Block a user