Fix compile crash when calling a function at global scope

This fixes a crash that occurs if a global variable is initialized
with the result of a function call.

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

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

native use(...);

f() {
	return 0;
}

new x = f();

main() {
	use(x);
}

----- end of test code -----
This commit is contained in:
Zeex 2014-01-01 13:08:21 +07:00
parent 0c8f23453e
commit c20d9cb33b

View File

@ -1967,6 +1967,12 @@ static int nesting=0;
lval_result->ident=iEXPRESSION; /* preset, may be changed later */
lval_result->constval=0;
lval_result->tag=sym->tag;
/* check whether we are inside a function */
if (curfunc==NULL) {
/* functions cannot be called at global scope */
error(29); /* invalid expression, assumed zero */
return;
}
/* check whether this is a function that returns an array */
symret=finddepend(sym);
assert(symret==NULL || symret->ident==iREFARRAY);