Fix compile crash when using CALL in #emit

This fixes a crash when calling a function with the CALL instruction in #emit.

Instead of merely writing a symbol's address to the .asm file we check
if we are in a CALL instruction, and if so we output the function's name
rather than its address.

See 7) here: http://forum.sa-mp.com/showthread.php?t=355877

--------- test code --------

foo() {}

main() {
	#emit call foo
}

----- end of test code -----
This commit is contained in:
Zeex 2014-01-02 04:54:02 +07:00
parent 23a4b5a18a
commit 8d238c4830

View File

@ -1220,7 +1220,12 @@ static int command(void)
if (sym==NULL || sym->ident!=iFUNCTN && sym->ident!=iREFFUNC && (sym->usage & uDEFINE)==0) {
error(17,str); /* undefined symbol */
} else {
outval(sym->addr,FALSE);
if (strcmp(name, "call")==0) {
assert((sym->ident & iFUNCTN)!=0 || (sym->ident & iREFFUNC)!=0);
stgwrite(sym->name);
} else {
outval(sym->addr,FALSE);
} /* if */
/* mark symbol as "used", unknown whether for read or write */
markusage(sym,uREAD | uWRITTEN);
code_idx+=opargs(1);