summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKpy! <ouroboros.ai@gmail.com>2015-04-22 17:36:17 +0200
committerKpy! <ouroboros.ai@gmail.com>2015-04-22 17:42:13 +0200
commit7e76bbb730679d4fe310198891499edeec241c31 (patch)
treeea2c78b4cc7cce2f79ee79f09e7955f5b433f8fe /src
parent79aa56c704ff4117511cd33be3efd0321683d89a (diff)
downloadhercules-7e76bbb730679d4fe310198891499edeec241c31.tar.gz
hercules-7e76bbb730679d4fe310198891499edeec241c31.tar.bz2
hercules-7e76bbb730679d4fe310198891499edeec241c31.tar.xz
hercules-7e76bbb730679d4fe310198891499edeec241c31.zip
Fix a crash condition when incorrectly using return outside the scope of a function or subroutine.
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/map/script.c b/src/map/script.c
index b355dfa9e..335f45509 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -5682,6 +5682,13 @@ BUILDIN(getarg)
/// return;
/// return <value>;
BUILDIN(return) {
+ st->state = RETFUNC;
+
+ if( st->stack->defsp < 1 || st->stack->stack_data[st->stack->defsp-1].type != C_RETINFO ) {
+ // Incorrect usage of return outside the scope of a function or subroutine.
+ return true; // No need for further processing, running script is about to be aborted.
+ }
+
if( script_hasdata(st,2) )
{// return value
struct script_data* data;
@@ -5712,7 +5719,7 @@ BUILDIN(return) {
{// no return value
script_pushnil(st);
}
- st->state = RETFUNC;
+
return true;
}