From c20d9cb33b45a4ce15f34b4536dd01b8c41ee214 Mon Sep 17 00:00:00 2001 From: Zeex Date: Wed, 1 Jan 2014 13:08:21 +0700 Subject: [PATCH] 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 ----- --- source/compiler/sc3.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/source/compiler/sc3.c b/source/compiler/sc3.c index ebd3ef6..af8437d 100644 --- a/source/compiler/sc3.c +++ b/source/compiler/sc3.c @@ -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);