Browse Source

Some friendlier error messages in cases where assert isn't really appropriate

master
Gavan Fantom 17 years ago
parent
commit
a4031c5ff8
  1. 27
      src/lsi/vm.c

27
src/lsi/vm.c

@ -861,7 +861,9 @@ void vm_load_file(char *filename)
char *ptr;
fh = fopen(filename, "r");
assert(fh != NULL);
if (fh == NULL) {
err(1, "Failed to open '%s'", filename);
}
for (ptr = vm_codearea; ptr < vm_codearea+vm_codesize; ptr++) {
int c;
@ -887,16 +889,19 @@ void vm_init_functions(void)
struct hashentry *ptr;
/* First, let's check the magic */
assert(vm_codearea[0] == MAGIC1);
assert(vm_codearea[1] == MAGIC2);
assert(vm_codearea[2] == VERSION1);
assert(vm_codearea[3] == VERSION2);
assert(GETINT(vm_codearea, 8) == vm_abiversion1);
assert(GETINT(vm_codearea, 12) == vm_abiversion2);
assert(GETINT(vm_codearea, 16) == vm_abiversion3);
assert(GETINT(vm_codearea, 20) == vm_abiversion4);
assert(GETINT(vm_codearea, 24) == vm_abiversion5);
if ((vm_codearea[0] != MAGIC1) ||
(vm_codearea[1] != MAGIC2))
errx(1, "Bad magic - not a lightscript binary");
if ((vm_codearea[2] != VERSION1) ||
(vm_codearea[3] != VERSION2))
errx(1, "Bad version - recompile");
if ((GETINT(vm_codearea, 8) != vm_abiversion1) ||
(GETINT(vm_codearea, 12) == vm_abiversion2) ||
(GETINT(vm_codearea, 16) == vm_abiversion3) ||
(GETINT(vm_codearea, 20) == vm_abiversion4) ||
(GETINT(vm_codearea, 24) == vm_abiversion5))
errx(1, "Incompatible ABI version - recompile");
/* Now, get the function table pointer */
t = GETINT(vm_codearea, 4);

Loading…
Cancel
Save