Fix compile crash on unknown assembly instruction

Make the assembler fail with a fatal error 104 "invalid assembler instruction"
if met an unknown instruction. It won't tell a correct line number though.
This commit is contained in:
Zeex 2014-01-04 14:36:06 +07:00
parent 6b0809a99e
commit 80eceb586d
2 changed files with 20 additions and 2 deletions

View File

@ -649,8 +649,10 @@ int pc_compile(int argc, char *argv[])
error(13); /* no entry point (no public functions) */
cleanup:
if (inpf!=NULL) /* main source file is not closed, do it now */
if (inpf!=NULL) { /* main source file is not closed, do it now */
pc_closesrc(inpf);
inpf=NULL;
}
/* write the binary file (the file is already open) */
if (!(sc_asmfile || sc_listing) && errnum==0 && jmpcode==0) {
assert(binf!=NULL);

View File

@ -211,6 +211,21 @@ static char *stripcomment(char *str)
return str;
}
static char *stripwhitespace(char *str)
{
if (*str!='\0') {
size_t len = strlen(str);
size_t i;
for (i=len-1; i>=0; i--) {
if (!isspace(str[i])) {
str[i+1]='\0';
break;
}
}
}
return str;
}
static void write_encoded(FILE *fbin,ucell *c,int num)
{
#if PAWN_CELL_SIZE == 16
@ -1016,7 +1031,8 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
/* nothing */;
assert(params>instr);
i=findopcode(instr,(int)(params-instr));
assert(opcodelist[i].name!=NULL);
if (opcodelist[i].name==NULL)
error(104, stripwhitespace(instr)); /* invalid assembler instruction */
if (opcodelist[i].segment==pass)
opcodelist[i].func(fout,skipwhitespace(params),opcodelist[i].opcode);
} /* while */