sprintf_malloc
This commit is contained in:
14
src/VM/VM.c
14
src/VM/VM.c
@@ -6,6 +6,18 @@ void VM_init(VM* vm){
|
||||
vm->state = VMState_Initialized;
|
||||
}
|
||||
|
||||
void VM_setErrorMessage(VM* vm, const char* format, ...){
|
||||
va_list argv;
|
||||
va_start(argv, format);
|
||||
char* NULLABLE(buf) = vsprintf_malloc(256, format, argv);
|
||||
va_end(argv);
|
||||
if(buf == NULL){
|
||||
buf = malloc(16);
|
||||
strcpy(buf, "SPRINTF FAILED");
|
||||
}
|
||||
vm->error_message = buf;
|
||||
}
|
||||
|
||||
bool VM_loadProgram(VM* vm, u8* data, size_t size){
|
||||
if(data == NULL){
|
||||
VM_setErrorMessage(vm, "[VM_loadProgram] can't load program because data == NULL");
|
||||
@@ -33,7 +45,7 @@ i32 VM_executeProgram(VM* vm){
|
||||
|
||||
const Instruction* instr = Instruction_getFromOpcode(opcode);
|
||||
if(instr == NULL){
|
||||
|
||||
VM_setErrorMessage(vm, "[%p] unknown opcode %02x", (void*)pos, opcode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user